package com.l7tech.gateway.common.entity;

import com.l7tech.gateway.common.custom.ClassNameToEntitySerializer;
import com.l7tech.gateway.common.custom.CustomEntitiesResolver;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.UsesEntities;
import com.l7tech.policy.assertion.ext.store.KeyValueStore;
import com.l7tech.util.Functions.Binary;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class EntitiesResolver {
   @Nullable
   private final CustomEntitiesResolver a;
   private static final String[] b;

   private EntitiesResolver(@NotNull EntitiesResolver.Builder var1) {
      if (var1 == null) {
         a(0);
      }

      super();
      this.a = var1.a != null ? new CustomEntitiesResolver(var1.a, var1.b) : null;
   }

   @NotNull
   public static EntitiesResolver.Builder builder() {
      return new EntitiesResolver.Builder();
   }

   @NotNull
   public static String getEntityTypeName(Assertion param0, @NotNull EntityType param1, @NotNull Binary<String, UsesEntities, EntityType> param2) {
      // $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 0f
      // 04: bipush 1
      // 05: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 08: goto 0f
      // 0b: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 0e: athrow
      // 0f: aload 2
      // 10: ifnonnull 1e
      // 13: bipush 2
      // 14: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 17: goto 1e
      // 1a: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 1d: athrow
      // 1e: aload 0
      // 1f: instanceof com/l7tech/policy/assertion/CustomAssertionHolder
      // 22: ifeq 40
      // 25: aload 1
      // 26: invokevirtual com/l7tech/objectmodel/EntityType.getName ()Ljava/lang/String;
      // 29: dup
      // 2a: ifnonnull 3f
      // 2d: goto 34
      // 30: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 33: athrow
      // 34: bipush 3
      // 35: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 38: goto 3f
      // 3b: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 3e: athrow
      // 3f: areturn
      // 40: aload 0
      // 41: instanceof com/l7tech/policy/assertion/UsesEntities
      // 44: ifeq 6c
      // 47: aload 2
      // 48: aload 0
      // 49: checkcast com/l7tech/policy/assertion/UsesEntities
      // 4c: aload 1
      // 4d: invokeinterface com/l7tech/util/Functions$Binary.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; 3
      // 52: checkcast java/lang/String
      // 55: dup
      // 56: ifnonnull 6b
      // 59: goto 60
      // 5c: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 5f: athrow
      // 60: bipush 4
      // 61: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 64: goto 6b
      // 67: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 6a: athrow
      // 6b: areturn
      // 6c: new java/lang/IllegalArgumentException
      // 6f: dup
      // 70: getstatic com/l7tech/gateway/common/entity/EntitiesResolver.b [Ljava/lang/String;
      // 73: bipush 7
      // 75: aaload
      // 76: invokespecial java/lang/IllegalArgumentException.<init> (Ljava/lang/String;)V
      // 79: athrow
      // try (0 -> 4): 5 java/lang/IllegalArgumentException
      // try (7 -> 11): 12 java/lang/IllegalArgumentException
      // try (14 -> 21): 22 java/lang/IllegalArgumentException
      // try (17 -> 26): 27 java/lang/IllegalArgumentException
      // try (30 -> 41): 42 java/lang/IllegalArgumentException
      // try (33 -> 46): 47 java/lang/IllegalArgumentException
   }

   @NotNull
   public EntityHeader[] getEntitiesUsed(@Nullable Assertion param1) {
      // $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: instanceof com/l7tech/policy/assertion/CustomAssertionHolder
      // 04: ifeq 37
      // 07: aload 0
      // 08: getfield com/l7tech/gateway/common/entity/EntitiesResolver.a Lcom/l7tech/gateway/common/custom/CustomEntitiesResolver;
      // 0b: ifnull 37
      // 0e: goto 15
      // 11: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 14: athrow
      // 15: aload 0
      // 16: getfield com/l7tech/gateway/common/entity/EntitiesResolver.a Lcom/l7tech/gateway/common/custom/CustomEntitiesResolver;
      // 19: aload 1
      // 1a: checkcast com/l7tech/policy/assertion/CustomAssertionHolder
      // 1d: invokevirtual com/l7tech/gateway/common/custom/CustomEntitiesResolver.getEntitiesUsed (Lcom/l7tech/policy/assertion/CustomAssertionHolder;)[Lcom/l7tech/objectmodel/EntityHeader;
      // 20: dup
      // 21: ifnonnull 36
      // 24: goto 2b
      // 27: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 2a: athrow
      // 2b: bipush 5
      // 2c: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 2f: goto 36
      // 32: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 35: athrow
      // 36: areturn
      // 37: aload 1
      // 38: instanceof com/l7tech/policy/assertion/UsesEntities
      // 3b: ifeq 5f
      // 3e: aload 1
      // 3f: checkcast com/l7tech/policy/assertion/UsesEntities
      // 42: invokeinterface com/l7tech/policy/assertion/UsesEntities.getEntitiesUsed ()[Lcom/l7tech/objectmodel/EntityHeader; 1
      // 47: dup
      // 48: ifnonnull 5e
      // 4b: goto 52
      // 4e: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 51: athrow
      // 52: bipush 6
      // 54: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 57: goto 5e
      // 5a: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 5d: athrow
      // 5e: areturn
      // 5f: bipush 0
      // 60: anewarray 62
      // 63: areturn
      // try (0 -> 6): 7 java/lang/IllegalArgumentException
      // try (3 -> 16): 17 java/lang/IllegalArgumentException
      // try (9 -> 21): 22 java/lang/IllegalArgumentException
      // try (25 -> 33): 34 java/lang/IllegalArgumentException
      // try (28 -> 38): 39 java/lang/IllegalArgumentException
   }

   public void replaceEntity(@Nullable Assertion param1, @NotNull EntityHeader param2, @NotNull EntityHeader param3) {
      // $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 2
      // 01: ifnonnull 10
      // 04: bipush 7
      // 06: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 09: goto 10
      // 0c: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 0f: athrow
      // 10: aload 3
      // 11: ifnonnull 20
      // 14: bipush 8
      // 16: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (I)V
      // 19: goto 20
      // 1c: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 1f: athrow
      // 20: aload 1
      // 21: instanceof com/l7tech/policy/assertion/CustomAssertionHolder
      // 24: ifeq 49
      // 27: aload 0
      // 28: getfield com/l7tech/gateway/common/entity/EntitiesResolver.a Lcom/l7tech/gateway/common/custom/CustomEntitiesResolver;
      // 2b: ifnull 49
      // 2e: goto 35
      // 31: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 34: athrow
      // 35: aload 0
      // 36: getfield com/l7tech/gateway/common/entity/EntitiesResolver.a Lcom/l7tech/gateway/common/custom/CustomEntitiesResolver;
      // 39: aload 2
      // 3a: aload 3
      // 3b: aload 1
      // 3c: checkcast com/l7tech/policy/assertion/CustomAssertionHolder
      // 3f: invokevirtual com/l7tech/gateway/common/custom/CustomEntitiesResolver.replaceEntity (Lcom/l7tech/objectmodel/EntityHeader;Lcom/l7tech/objectmodel/EntityHeader;Lcom/l7tech/policy/assertion/CustomAssertionHolder;)V
      // 42: goto 62
      // 45: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 48: athrow
      // 49: aload 1
      // 4a: instanceof com/l7tech/policy/assertion/UsesEntities
      // 4d: ifeq 62
      // 50: aload 1
      // 51: checkcast com/l7tech/policy/assertion/UsesEntities
      // 54: aload 2
      // 55: aload 3
      // 56: invokeinterface com/l7tech/policy/assertion/UsesEntities.replaceEntity (Lcom/l7tech/objectmodel/EntityHeader;Lcom/l7tech/objectmodel/EntityHeader;)V 3
      // 5b: goto 62
      // 5e: invokestatic com/l7tech/gateway/common/entity/EntitiesResolver.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 61: athrow
      // 62: return
      // try (0 -> 4): 5 java/lang/IllegalArgumentException
      // try (7 -> 11): 12 java/lang/IllegalArgumentException
      // try (14 -> 20): 21 java/lang/IllegalArgumentException
      // try (17 -> 31): 31 java/lang/IllegalArgumentException
      // try (33 -> 41): 42 java/lang/IllegalArgumentException
   }

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

   static {
      String[] var5 = new String[15];
      int var3 = 0;
      String var2 = "\t{+<b/!\u001ag\u000b\u0000|>\u0006\u000fs:1\rq2V`l<\u000b}7Vk:<\u000bi>\u0000#8'\u0003s0\u0017#>&\u001aw+\u0000#\u001e&\u001aw+\u0010i(\u001a\u000bm0\u0015z>:1\rq2V`l<\u000b}7Vk:<\u000bi>\u0000#8'\u0003s0\u0017#>&\u001aw+\u0000#\u001e&\u001aw+\u0010i(\u001a\u000bm0\u0015z>:\u0007\fk6\u0015h>:\u0011\t{+<b/!\u001ag\u000b\u0000|>\u0006\u000fs:\u0012\u001bm:\nI5<\u0007j6\u001c\u007f\u000f1\u001e{\u0019\u0017\u000f\t{+<b/!\u001aw:\nY(-\nh;p,\f|+'\u001cj:\u001d,:;\u001d{-\re4&Nj&\tiuh/m,\u001c~/!\u0001p\u007f\u0014y(<N|:Y\u007f.8\u000bl<\u0015m(;Nq9Yi2<\u0006{-YY(-\u001d[1\re/!\u000bm\u007f\u0016~{\u000b\u001bm+\u0016a\u001a;\u001d{-\re4&&q3\u001di)\u0006Rw1\u0010xe>/l8\fa>&\u001a>9\u0016~{\b q+7y7$Nn>\u000bm6-\u001a{-Y+~;I>0\u001f,~;@;,Ya.;\u001a>1\u0016x{*\u000b>1\f`7*.P0\rB.$\u0002>2\u001cx3'\n>z\n\"~;Ns*\nx{&\u0001j\u007f\u000bi/=\u001cp\u007f\u0017y7$\u0004\u001ag/\u001c\r\u001c{/\u0015m8-+p+\u0010x\"";
      int var4 = "\t{+<b/!\u001ag\u000b\u0000|>\u0006\u000fs:1\rq2V`l<\u000b}7Vk:<\u000bi>\u0000#8'\u0003s0\u0017#>&\u001aw+\u0000#\u001e&\u001aw+\u0010i(\u001a\u000bm0\u0015z>:1\rq2V`l<\u000b}7Vk:<\u000bi>\u0000#8'\u0003s0\u0017#>&\u001aw+\u0000#\u001e&\u001aw+\u0010i(\u001a\u000bm0\u0015z>:\u0007\fk6\u0015h>:\u0011\t{+<b/!\u001ag\u000b\u0000|>\u0006\u000fs:\u0012\u001bm:\nI5<\u0007j6\u001c\u007f\u000f1\u001e{\u0019\u0017\u000f\t{+<b/!\u001aw:\nY(-\nh;p,\f|+'\u001cj:\u001d,:;\u001d{-\re4&Nj&\tiuh/m,\u001c~/!\u0001p\u007f\u0014y(<N|:Y\u007f.8\u000bl<\u0015m(;Nq9Yi2<\u0006{-YY(-\u001d[1\re/!\u000bm\u007f\u0016~{\u000b\u001bm+\u0016a\u001a;\u001d{-\re4&&q3\u001di)\u0006Rw1\u0010xe>/l8\fa>&\u001a>9\u0016~{\b q+7y7$Nn>\u000bm6-\u001a{-Y+~;I>0\u001f,~;@;,Ya.;\u001a>1\u0016x{*\u000b>1\f`7*.P0\rB.$\u0002>2\u001cx3'\n>z\n\"~;Ns*\nx{&\u0001j\u007f\u000bi/=\u001cp\u007f\u0017y7$\u0004\u001ag/\u001c\r\u001c{/\u0015m8-+p+\u0010x\""
         .length();
      char var1 = 17;
      int var7 = -1;

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

         while (true) {
            String var8 = a(var10000, a(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 = "\tz34j')\u0012o\t\bs 4j')\u0012o";
                  var4 = "\tz34j')\u0012o\t\bs 4j')\u0012o".length();
                  var1 = '\t';
                  var7 = -1;
            }

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

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

      return var10000;
   }

   private static String a(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 -> 59;
            case 1 -> 75;
            case 2 -> 10;
            case 3 -> 44;
            case 4 -> 89;
            case 5 -> 14;
            default -> 29;
         });
      }

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

   public static class Builder {
      @Nullable
      private KeyValueStore a;
      @Nullable
      private ClassNameToEntitySerializer b;

      private Builder() {
      }

      public EntitiesResolver.Builder keyValueStore(@Nullable KeyValueStore var1) {
         this.a = var1;
         return this;
      }

      public EntitiesResolver.Builder classNameToSerializer(@Nullable ClassNameToEntitySerializer var1) {
         this.b = var1;
         return this;
      }

      public EntitiesResolver build() {
         return new EntitiesResolver(this);
      }
   }
}
