package com.l7tech.policy.code.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.l7tech.policy.assertion.CustomAssertionHolder;
import com.l7tech.policy.code.config.AssertionTypeConfig;
import com.l7tech.policy.code.config.PolicyCodeConfig;
import com.l7tech.util.HexUtils;
import com.l7tech.util.PoolByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class CustomAssertionSerializer extends BasicAssertionSerializer<CustomAssertionHolder> {
   private static final String a;
   private static final String b;
   private static final String c;
   private static final String d;
   private static final String[] f;

   public CustomAssertionSerializer(PolicyCodeConfig var1) {
      super(var1);
   }

   protected void serializeAssertion(CustomAssertionHolder param1, AssertionTypeConfig param2, JsonGenerator param3, SerializerProvider param4) throws IOException {
      // $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 0
      // 01: getfield com/l7tech/policy/code/serializer/CustomAssertionSerializer.codeConfig Lcom/l7tech/policy/code/config/PolicyCodeConfig;
      // 04: invokevirtual com/l7tech/policy/code/config/PolicyCodeConfig.getFieldSerializer ()Lcom/l7tech/policy/code/serializer/FieldSerializer;
      // 07: astore 5
      // 09: aload 3
      // 0a: getstatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.f [Ljava/lang/String;
      // 0d: bipush 2
      // 0e: aaload
      // 0f: invokevirtual com/fasterxml/jackson/core/JsonGenerator.writeObjectFieldStart (Ljava/lang/String;)V
      // 12: aload 0
      // 13: aload 1
      // 14: aload 2
      // 15: aload 3
      // 16: invokevirtual com/l7tech/policy/code/serializer/CustomAssertionSerializer.serializeAssertionProperties (Lcom/l7tech/policy/assertion/Assertion;Lcom/l7tech/policy/code/config/AssertionTypeConfig;Lcom/fasterxml/jackson/core/JsonGenerator;)V
      // 19: aload 1
      // 1a: invokevirtual com/l7tech/policy/assertion/CustomAssertionHolder.getCustomAssertion ()Lcom/l7tech/policy/assertion/ext/CustomAssertion;
      // 1d: ifnonnull 31
      // 20: new java/io/IOException
      // 23: dup
      // 24: getstatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.f [Ljava/lang/String;
      // 27: bipush 3
      // 28: aaload
      // 29: invokespecial java/io/IOException.<init> (Ljava/lang/String;)V
      // 2c: athrow
      // 2d: invokestatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 30: athrow
      // 31: aload 3
      // 32: getstatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.f [Ljava/lang/String;
      // 35: bipush 8
      // 37: aaload
      // 38: aload 1
      // 39: invokevirtual com/l7tech/policy/assertion/CustomAssertionHolder.getCustomAssertion ()Lcom/l7tech/policy/assertion/ext/CustomAssertion;
      // 3c: invokeinterface com/l7tech/policy/assertion/ext/CustomAssertion.getName ()Ljava/lang/String; 1
      // 41: invokevirtual com/fasterxml/jackson/core/JsonGenerator.writeStringField (Ljava/lang/String;Ljava/lang/String;)V
      // 44: aload 0
      // 45: getfield com/l7tech/policy/code/serializer/CustomAssertionSerializer.codeConfig Lcom/l7tech/policy/code/config/PolicyCodeConfig;
      // 48: invokevirtual com/l7tech/policy/code/config/PolicyCodeConfig.useLegacyCustomAssertionSerializer ()Z
      // 4b: ifeq 78
      // 4e: aload 0
      // 4f: getfield com/l7tech/policy/code/serializer/CustomAssertionSerializer.codeConfig Lcom/l7tech/policy/code/config/PolicyCodeConfig;
      // 52: invokevirtual com/l7tech/policy/code/config/PolicyCodeConfig.isNotSerializeDefaultFields ()Z
      // 55: ifeq 78
      // 58: goto 5f
      // 5b: invokestatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 5e: athrow
      // 5f: aload 3
      // 60: getstatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.f [Ljava/lang/String;
      // 63: bipush 6
      // 65: aaload
      // 66: aload 0
      // 67: aload 1
      // 68: invokevirtual com/l7tech/policy/assertion/CustomAssertionHolder.getCustomAssertion ()Lcom/l7tech/policy/assertion/ext/CustomAssertion;
      // 6b: invokevirtual com/l7tech/policy/code/serializer/CustomAssertionSerializer.a (Ljava/io/Serializable;)Ljava/lang/String;
      // 6e: invokevirtual com/fasterxml/jackson/core/JsonGenerator.writeStringField (Ljava/lang/String;Ljava/lang/String;)V
      // 71: goto d1
      // 74: invokestatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 77: athrow
      // 78: aload 1
      // 79: invokevirtual com/l7tech/policy/assertion/CustomAssertionHolder.getCustomAssertion ()Lcom/l7tech/policy/assertion/ext/CustomAssertion;
      // 7c: invokeinterface com/l7tech/policy/assertion/ext/CustomAssertion.getClass ()Ljava/lang/Class; 1
      // 81: astore 6
      // 83: aload 3
      // 84: getstatic com/l7tech/policy/code/serializer/CustomAssertionSerializer.f [Ljava/lang/String;
      // 87: astore 9
      // 89: aload 9
      // 8b: bipush 1
      // 8c: aaload
      // 8d: aload 6
      // 8f: invokevirtual java/lang/Class.getName ()Ljava/lang/String;
      // 92: invokevirtual com/fasterxml/jackson/core/JsonGenerator.writeStringField (Ljava/lang/String;Ljava/lang/String;)V
      // 95: aload 0
      // 96: getfield com/l7tech/policy/code/serializer/CustomAssertionSerializer.codeConfig Lcom/l7tech/policy/code/config/PolicyCodeConfig;
      // 99: aload 6
      // 9b: invokevirtual java/lang/Class.getName ()Ljava/lang/String;
      // 9e: invokestatic com/l7tech/policy/assertion/CustomAssertionHolder.getExternalNameFrom (Ljava/lang/String;)Ljava/lang/String;
      // a1: invokevirtual com/l7tech/policy/code/config/PolicyCodeConfig.getTypeConfigByExtName (Ljava/lang/String;)Lcom/l7tech/policy/code/config/AssertionTypeConfig;
      // a4: astore 7
      // a6: aload 7
      // a8: aload 6
      // aa: invokevirtual com/l7tech/policy/code/config/AssertionTypeConfig.getBeanTypeConfigSilently (Ljava/lang/Class;)Lcom/l7tech/policy/code/config/BeanTypeConfig;
      // ad: astore 8
      // af: aload 3
      // b0: aload 9
      // b2: bipush 9
      // b4: aaload
      // b5: invokevirtual com/fasterxml/jackson/core/JsonGenerator.writeObjectFieldStart (Ljava/lang/String;)V
      // b8: aload 8
      // ba: invokevirtual com/l7tech/policy/code/config/BeanTypeConfig.getOrderedFields ()Ljava/util/List;
      // bd: aload 5
      // bf: aload 1
      // c0: aload 8
      // c2: aload 3
      // c3: invokedynamic accept (Lcom/l7tech/policy/code/serializer/FieldSerializer;Lcom/l7tech/policy/assertion/CustomAssertionHolder;Lcom/l7tech/policy/code/config/BeanTypeConfig;Lcom/fasterxml/jackson/core/JsonGenerator;)Ljava/util/function/Consumer; bsm=java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; args=[ (Ljava/lang/Object;)V, com/l7tech/policy/code/serializer/CustomAssertionSerializer.lambda$serializeAssertion$0 (Lcom/l7tech/policy/code/serializer/FieldSerializer;Lcom/l7tech/policy/assertion/CustomAssertionHolder;Lcom/l7tech/policy/code/config/BeanTypeConfig;Lcom/fasterxml/jackson/core/JsonGenerator;Lcom/l7tech/policy/code/config/FieldTypeConfig;)V, (Lcom/l7tech/policy/code/config/FieldTypeConfig;)V ]
      // c8: invokeinterface java/util/List.forEach (Ljava/util/function/Consumer;)V 2
      // cd: aload 3
      // ce: invokevirtual com/fasterxml/jackson/core/JsonGenerator.writeEndObject ()V
      // d1: aload 3
      // d2: invokevirtual com/fasterxml/jackson/core/JsonGenerator.writeEndObject ()V
      // d5: return
      // try (4 -> 24): 24 java/io/IOException
      // try (26 -> 42): 43 java/io/IOException
      // try (38 -> 55): 55 java/io/IOException
   }

   private String a(Serializable var1) throws IOException {
      PoolByteArrayOutputStream var2 = new PoolByteArrayOutputStream();

      String var5;
      try {
         ObjectOutputStream var3 = new ObjectOutputStream(var2);
         var3.writeObject(var1);
         String var4 = HexUtils.encodeBase64(var2.toByteArray(), true);
         var3.close();
         var5 = var4;
      } catch (Throwable var7) {
         try {
            var2.close();
         } catch (Throwable var6) {
            var7.addSuppressed(var6);
         }

         throw var7;
      }

      var2.close();
      return var5;
   }

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

   static {
      String[] var5 = new String[10];
      int var3 = 0;
      String var2 = "\u000f.vF\n\u0017.wV$+\u0018\u0000<h\u000f\":hW.\u00055\u0012<~Q5\u0001\u001b\u000f\u0018\":hW.\u0005T\u0000<hF3\u001c\u001d\u000e!;J2H\u001a\u0014#w\u000b\u0003.hFw\\\"\u0000#nF\n\u0017.wV$+\u0018\u0000<h\u000b\u0003.hFw\\\"\u0000#nF\u0005\u0017.wV$";
      int var4 = "\u000f.vF\n\u0017.wV$+\u0018\u0000<h\u000f\":hW.\u00055\u0012<~Q5\u0001\u001b\u000f\u0018\":hW.\u0005T\u0000<hF3\u001c\u001d\u000e!;J2H\u001a\u0014#w\u000b\u0003.hFw\\\"\u0000#nF\n\u0017.wV$+\u0018\u0000<h\u000b\u0003.hFw\\\"\u0000#nF\u0005\u0017.wV$"
         .length();
      char var1 = 4;
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 80;
         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) {
                     f = var5;
                     String[] var9 = f;
                     b = f[4];
                     a = var9[0];
                     c = var9[7];
                     d = var9[5];
                     return;
                  }

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

                  var2 = "kJ\u0012\"\u0005sJ\u00132@";
                  var4 = "kJ\u0012\"\u0005sJ\u00132@".length();
                  var1 = 4;
                  var7 = -1;
            }

            var10000 = 52;
            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] ^ 36);
      }

      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 -> 49;
            case 1 -> 31;
            case 2 -> 75;
            case 3 -> 115;
            case 4 -> 17;
            case 5 -> 56;
            default -> 36;
         });
      }

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