package com.l7tech.server.custom.format;

import com.l7tech.gateway.common.custom.JsonDataToCustomConverter;
import com.l7tech.json.InvalidJsonException;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.ext.message.CustomJsonData;
import com.l7tech.policy.assertion.ext.message.CustomMessage;
import com.l7tech.policy.assertion.ext.message.CustomMessageAccessException;
import com.l7tech.server.StashManagerFactory;
import com.l7tech.server.custom.CustomMessageImpl;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;

public class CustomMessageJsonFormat extends CustomMessageFormatBase<CustomJsonData> {
   private static final String[] b;

   public CustomMessageJsonFormat(@NotNull StashManagerFactory var1, @NotNull String var2, @NotNull String var3) {
      if (var1 == null) {
         b(0);
      }

      if (var2 == null) {
         b(1);
      }

      if (var3 == null) {
         b(2);
      }

      super(var1, var2, var3);
   }

   public Class<CustomJsonData> getRepresentationClass() {
      return CustomJsonData.class;
   }

   public CustomJsonData extract(CustomMessage var1) throws CustomMessageAccessException {
      try {
         if (var1 == null) {
            throw new CustomMessageAccessException(b[9]);
         }
      } catch (IOException var4) {
         throw a(var4);
      }

      try {
         if (!(var1 instanceof CustomMessageImpl)) {
            throw new CustomMessageAccessException(b[0]);
         }
      } catch (IOException var7) {
         throw a(var7);
      }

      Message var2 = ((CustomMessageImpl)var1).getMessage();

      try {
         try {
            if (!var2.isInitialized() || !var2.isJson()) {
               return null;
            }
         } catch (IOException var5) {
            throw a(var5);
         }

         return new JsonDataToCustomConverter(var2.getJsonKnob().getJsonData());
      } catch (IOException | InvalidJsonException var6) {
         throw new CustomMessageAccessException(b[6], var6);
      }
   }

   public void overwrite(CustomMessage param1, CustomJsonData param2) throws CustomMessageAccessException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 1
      // 01: ifnonnull 15
      // 04: new com/l7tech/policy/assertion/ext/message/CustomMessageAccessException
      // 07: dup
      // 08: getstatic com/l7tech/server/custom/format/CustomMessageJsonFormat.b [Ljava/lang/String;
      // 0b: bipush 2
      // 0c: aaload
      // 0d: invokespecial com/l7tech/policy/assertion/ext/message/CustomMessageAccessException.<init> (Ljava/lang/String;)V
      // 10: athrow
      // 11: invokestatic com/l7tech/server/custom/format/CustomMessageJsonFormat.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 14: athrow
      // 15: aload 1
      // 16: instanceof com/l7tech/server/custom/CustomMessageImpl
      // 19: ifne 2d
      // 1c: new com/l7tech/policy/assertion/ext/message/CustomMessageAccessException
      // 1f: dup
      // 20: getstatic com/l7tech/server/custom/format/CustomMessageJsonFormat.b [Ljava/lang/String;
      // 23: bipush 5
      // 24: aaload
      // 25: invokespecial com/l7tech/policy/assertion/ext/message/CustomMessageAccessException.<init> (Ljava/lang/String;)V
      // 28: athrow
      // 29: invokestatic com/l7tech/server/custom/format/CustomMessageJsonFormat.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 2c: athrow
      // 2d: aload 1
      // 2e: checkcast com/l7tech/server/custom/CustomMessageImpl
      // 31: invokevirtual com/l7tech/server/custom/CustomMessageImpl.getMessage ()Lcom/l7tech/message/Message;
      // 34: astore 3
      // 35: aload 2
      // 36: ifnull 5f
      // 39: aload 2
      // 3a: invokeinterface com/l7tech/policy/assertion/ext/message/CustomJsonData.getJsonData ()Ljava/lang/String; 1
      // 3f: ifnull 59
      // 42: goto 49
      // 45: invokestatic com/l7tech/server/custom/format/CustomMessageJsonFormat.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 48: athrow
      // 49: aload 2
      // 4a: invokeinterface com/l7tech/policy/assertion/ext/message/CustomJsonData.getJsonData ()Ljava/lang/String; 1
      // 4f: invokevirtual java/lang/String.getBytes ()[B
      // 52: goto 62
      // 55: invokestatic com/l7tech/server/custom/format/CustomMessageJsonFormat.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 58: athrow
      // 59: bipush 0
      // 5a: newarray 8
      // 5c: goto 62
      // 5f: bipush 0
      // 60: newarray 8
      // 62: astore 4
      // 64: aload 3
      // 65: getstatic com/l7tech/common/mime/ContentTypeHeader.APPLICATION_JSON Lcom/l7tech/common/mime/ContentTypeHeader;
      // 68: aload 4
      // 6a: invokevirtual com/l7tech/message/Message.initialize (Lcom/l7tech/common/mime/ContentTypeHeader;[B)V
      // 6d: goto 82
      // 70: astore 4
      // 72: new com/l7tech/policy/assertion/ext/message/CustomMessageAccessException
      // 75: dup
      // 76: getstatic com/l7tech/server/custom/format/CustomMessageJsonFormat.b [Ljava/lang/String;
      // 79: bipush 14
      // 7b: aaload
      // 7c: aload 4
      // 7e: invokespecial com/l7tech/policy/assertion/ext/message/CustomMessageAccessException.<init> (Ljava/lang/String;Ljava/lang/Throwable;)V
      // 81: athrow
      // 82: return
      // try (29 -> 39): 39 java/io/IOException
      // try (27 -> 32): 33 java/io/IOException
      // try (11 -> 21): 21 java/io/IOException
      // try (0 -> 9): 9 java/io/IOException
      // try (27 -> 51): 52 java/io/IOException
   }

   public <K> CustomJsonData createBody(K param1) throws CustomMessageAccessException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 1
      // 01: ifnonnull 16
      // 04: new com/l7tech/policy/assertion/ext/message/CustomMessageAccessException
      // 07: dup
      // 08: getstatic com/l7tech/server/custom/format/CustomMessageJsonFormat.b [Ljava/lang/String;
      // 0b: bipush 7
      // 0d: aaload
      // 0e: invokespecial com/l7tech/policy/assertion/ext/message/CustomMessageAccessException.<init> (Ljava/lang/String;)V
      // 11: athrow
      // 12: invokestatic com/l7tech/server/custom/format/CustomMessageJsonFormat.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 15: athrow
      // 16: aload 1
      // 17: instanceof java/lang/String
      // 1a: ifeq 33
      // 1d: new com/l7tech/gateway/common/custom/JsonDataToCustomConverter
      // 20: dup
      // 21: getstatic com/l7tech/json/JSONFactory.INSTANCE Lcom/l7tech/json/JSONFactory;
      // 24: aload 1
      // 25: checkcast java/lang/String
      // 28: invokevirtual com/l7tech/json/JSONFactory.newJsonData (Ljava/lang/String;)Lcom/l7tech/json/JSONData;
      // 2b: invokespecial com/l7tech/gateway/common/custom/JsonDataToCustomConverter.<init> (Lcom/l7tech/json/JSONData;)V
      // 2e: areturn
      // 2f: invokestatic com/l7tech/server/custom/format/CustomMessageJsonFormat.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 32: athrow
      // 33: aload 1
      // 34: instanceof java/io/InputStream
      // 37: ifeq ac
      // 3a: sipush 16384
      // 3d: invokestatic com/l7tech/util/BufferPool.getBuffer (I)[B
      // 40: astore 2
      // 41: aload 1
      // 42: checkcast java/io/InputStream
      // 45: astore 3
      // 46: new java/lang/StringBuilder
      // 49: dup
      // 4a: invokespecial java/lang/StringBuilder.<init> ()V
      // 4d: astore 4
      // 4f: aload 3
      // 50: aload 2
      // 51: invokevirtual java/io/InputStream.read ([B)I
      // 54: dup
      // 55: istore 5
      // 57: ifle 72
      // 5a: aload 4
      // 5c: new java/lang/String
      // 5f: dup
      // 60: aload 2
      // 61: bipush 0
      // 62: iload 5
      // 64: invokespecial java/lang/String.<init> ([BII)V
      // 67: invokevirtual java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
      // 6a: pop
      // 6b: goto 4f
      // 6e: invokestatic com/l7tech/server/custom/format/CustomMessageJsonFormat.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 71: athrow
      // 72: new com/l7tech/gateway/common/custom/JsonDataToCustomConverter
      // 75: dup
      // 76: getstatic com/l7tech/json/JSONFactory.INSTANCE Lcom/l7tech/json/JSONFactory;
      // 79: aload 4
      // 7b: invokevirtual java/lang/StringBuilder.toString ()Ljava/lang/String;
      // 7e: invokevirtual com/l7tech/json/JSONFactory.newJsonData (Ljava/lang/String;)Lcom/l7tech/json/JSONData;
      // 81: invokespecial com/l7tech/gateway/common/custom/JsonDataToCustomConverter.<init> (Lcom/l7tech/json/JSONData;)V
      // 84: astore 6
      // 86: aload 2
      // 87: invokestatic com/l7tech/util/BufferPool.returnBuffer ([B)Z
      // 8a: pop
      // 8b: aload 6
      // 8d: areturn
      // 8e: astore 3
      // 8f: new com/l7tech/policy/assertion/ext/message/CustomMessageAccessException
      // 92: dup
      // 93: getstatic com/l7tech/server/custom/format/CustomMessageJsonFormat.b [Ljava/lang/String;
      // 96: astore 8
      // 98: aload 8
      // 9a: bipush 10
      // 9c: aaload
      // 9d: aload 3
      // 9e: invokespecial com/l7tech/policy/assertion/ext/message/CustomMessageAccessException.<init> (Ljava/lang/String;Ljava/lang/Throwable;)V
      // a1: athrow
      // a2: astore 7
      // a4: aload 2
      // a5: invokestatic com/l7tech/util/BufferPool.returnBuffer ([B)Z
      // a8: pop
      // a9: aload 7
      // ab: athrow
      // ac: goto c3
      // af: astore 2
      // b0: new com/l7tech/policy/assertion/ext/message/CustomMessageAccessException
      // b3: dup
      // b4: getstatic com/l7tech/server/custom/format/CustomMessageJsonFormat.b [Ljava/lang/String;
      // b7: astore 8
      // b9: aload 8
      // bb: bipush 8
      // bd: aaload
      // be: aload 2
      // bf: invokespecial com/l7tech/policy/assertion/ext/message/CustomMessageAccessException.<init> (Ljava/lang/String;Ljava/lang/Throwable;)V
      // c2: athrow
      // c3: new com/l7tech/policy/assertion/ext/message/CustomMessageAccessException
      // c6: dup
      // c7: aload 1
      // c8: invokevirtual java/lang/Object.getClass ()Ljava/lang/Class;
      // cb: invokevirtual java/lang/Class.getSimpleName ()Ljava/lang/String;
      // ce: getstatic com/l7tech/server/custom/format/CustomMessageJsonFormat.b [Ljava/lang/String;
      // d1: bipush 1
      // d2: aaload
      // d3: swap
      // d4: invokedynamic makeConcatWithConstants (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; bsm=java/lang/invoke/StringConcatFactory.makeConcatWithConstants (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ "\u0001\u0001" ]
      // d9: invokespecial com/l7tech/policy/assertion/ext/message/CustomMessageAccessException.<init> (Ljava/lang/String;)V
      // dc: athrow
      // try (42 -> 53): 53 java/io/IOException
      // try (0 -> 9): 9 java/io/IOException
      // try (30 -> 63): 68 java/io/IOException
      // try (30 -> 63): 79 null
      // try (68 -> 80): 79 null
      // try (11 -> 21): 86 com/l7tech/json/InvalidJsonException
      // try (11 -> 22): 22 java/io/IOException
      // try (24 -> 66): 86 com/l7tech/json/InvalidJsonException
      // try (68 -> 85): 86 com/l7tech/json/InvalidJsonException
   }

   private static Exception a(Exception var0) {
      return var0;
   }

   static {
      String[] var5 = new String[16];
      int var3 = 0;
      String var2 = "+deUQI\"fhe\u0006_Hg3oeS@^(4usB\u0010Z>6d\u001a\u0013oeS@^(4usB\u0010M((usHD\u000e3?qs\u001c\u0010\u0016+deUQI\"fbwH^A3fcs\u0006^[+*7%n{\t\\\u00193#b~\tCK50dd\tS[42n{\tVA5+`b\ts[42n{kU]4'fslCA)\u0000ndKQZ>\u0007sqS]K)2!pIB\u000e\u0007\bnbhEB+fqwTQC\"2dd\u0006\u0017\u000b4a!y@\u0010\u000b4h$e\u0006][42!xID\u000e%#!xS\\B\u001e+deUQI\"fhe\u0006_Hg3oeS@^(4usB\u0010Z>6d)\u0003sdIB\u000e0.hzC\u0010K?2swEDG)!!\\u\u007f`g+deUQI\"fwwJEK\u0016%nxRU@3fbwH^A3fcs\u0006^[+*\f\u000fo`G\\G#fKEi~\u0016+deUQI\"fbwH^A3fcs\u0006^[+*4\u0003sdIB\u000e0.hzC\u0010M5#`bO^Ig\u0005teR_C\r5nxbQZ&fgdI]\u000e\u000e(qcRcZ5#`{\u0004(`{C\u0006zhxOD\u0010\u00135uwUXc&(`qCBh&%uyTI";
      int var4 = "+deUQI\"fhe\u0006_Hg3oeS@^(4usB\u0010Z>6d\u001a\u0013oeS@^(4usB\u0010M((usHD\u000e3?qs\u001c\u0010\u0016+deUQI\"fbwH^A3fcs\u0006^[+*7%n{\t\\\u00193#b~\tCK50dd\tS[42n{\tVA5+`b\ts[42n{kU]4'fslCA)\u0000ndKQZ>\u0007sqS]K)2!pIB\u000e\u0007\bnbhEB+fqwTQC\"2dd\u0006\u0017\u000b4a!y@\u0010\u000b4h$e\u0006][42!xID\u000e%#!xS\\B\u001e+deUQI\"fhe\u0006_Hg3oeS@^(4usB\u0010Z>6d)\u0003sdIB\u000e0.hzC\u0010K?2swEDG)!!\\u\u007f`g+deUQI\"fwwJEK\u0016%nxRU@3fbwH^A3fcs\u0006^[+*\f\u000fo`G\\G#fKEi~\u0016+deUQI\"fbwH^A3fcs\u0006^[+*4\u0003sdIB\u000e0.hzC\u0010M5#`bO^Ig\u0005teR_C\r5nxbQZ&fgdI]\u000e\u000e(qcRcZ5#`{\u0004(`{C\u0006zhxOD\u0010\u00135uwUXc&(`qCBh&%uyTI"
         .length();
      char var1 = 30;
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 64;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = b(var10000, b(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     b = var5;
                     return;
                  }

                  var1 = var2.charAt(var7);
                  break;
               default:
                  var5[var3++] = var8;
                  if ((var7 += var1) < var4) {
                     var1 = var2.charAt(var7);
                     continue label24;
                  }

                  var2 = "y\t\u001e38tJT\u0012\u00009j;KY\t\u001b.# TR\u001cL\u0016\u0019\u001bs\u001c\u0016\t/95ZY[\u001a=&!X\u000bX\u001e\u001f?8=MH\u0012\u00032";
                  var4 = "y\t\u001e38tJT\u0012\u00009j;KY\t\u001b.# TR\u001cL\u0016\u0019\u001bs\u001c\u0016\t/95ZY[\u001a=&!X\u000bX\u001e\u001f?8=MH\u0012\u00032"
                     .length();
                  var1 = '*';
                  var7 = -1;
            }

            var10000 = 58;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

   private static char[] b(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 7);
      }

      return var10000;
   }

   private static String b(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 6;
            case 1 -> 65;
            case 2 -> 86;
            case 3 -> 102;
            case 4 -> 112;
            case 5 -> 110;
            default -> 7;
         });
      }

      return new String(var10001).intern();
   }
}
