package com.l7tech.policy;

import com.l7tech.objectmodel.GuidBasedEntityManager;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.AssertionTranslator;
import com.l7tech.policy.assertion.Include;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.composite.CompositeAssertion;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.jetbrains.annotations.Nullable;

public class IncludeAssertionDereferenceTranslator implements AssertionTranslator {
   private final GuidBasedEntityManager<Policy> a;
   private final Set<String> b;
   private final boolean c;
   private final boolean d;
   private static final String[] e;

   public IncludeAssertionDereferenceTranslator(GuidBasedEntityManager<Policy> var1) {
      this(var1, new HashSet<>(), true, true);
   }

   public IncludeAssertionDereferenceTranslator(GuidBasedEntityManager<Policy> var1, Set<String> var2, boolean var3, boolean var4) {
      if (var2 == null) {
         String[] var5 = e;
         throw new NullPointerException(var5[3]);
      }

      try {
         if (var1 == null) {
            throw new NullPointerException(e[2]);
         }
      } catch (NullPointerException var6) {
         throw a(var6);
      }

      this.a = var1;
      this.b = var2;
      this.c = var3;
      this.d = var4;
   }

   @Override
   public Assertion translate(@Nullable Assertion param1) throws PolicyAssertionException {
      // $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:
      // 000: aload 1
      // 001: instanceof com/l7tech/policy/assertion/Include
      // 004: ifne 00d
      // 007: aload 1
      // 008: areturn
      // 009: invokestatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 00c: athrow
      // 00d: aload 1
      // 00e: checkcast com/l7tech/policy/assertion/Include
      // 011: astore 2
      // 012: aload 0
      // 013: getfield com/l7tech/policy/IncludeAssertionDereferenceTranslator.d Z
      // 016: ifne 02d
      // 019: aload 2
      // 01a: invokevirtual com/l7tech/policy/assertion/Include.isEnabled ()Z
      // 01d: ifne 02d
      // 020: goto 027
      // 023: invokestatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 026: athrow
      // 027: aload 1
      // 028: areturn
      // 029: invokestatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 02c: athrow
      // 02d: aload 2
      // 02e: invokevirtual com/l7tech/policy/assertion/Include.retrieveFragmentPolicy ()Lcom/l7tech/policy/Policy;
      // 031: astore 3
      // 032: aload 0
      // 033: getfield com/l7tech/policy/IncludeAssertionDereferenceTranslator.b Ljava/util/Set;
      // 036: aload 2
      // 037: invokevirtual com/l7tech/policy/assertion/Include.getPolicyGuid ()Ljava/lang/String;
      // 03a: invokeinterface java/util/Set.add (Ljava/lang/Object;)Z 2
      // 03f: ifne 05e
      // 042: new com/l7tech/policy/assertion/PolicyAssertionException
      // 045: dup
      // 046: aload 2
      // 047: aload 2
      // 048: invokevirtual com/l7tech/policy/assertion/Include.getPolicyGuid ()Ljava/lang/String;
      // 04b: getstatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.e [Ljava/lang/String;
      // 04e: bipush 0
      // 04f: aaload
      // 050: swap
      // 051: 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" ]
      // 056: invokespecial com/l7tech/policy/assertion/PolicyAssertionException.<init> (Lcom/l7tech/policy/assertion/Assertion;Ljava/lang/String;)V
      // 059: athrow
      // 05a: invokestatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 05d: athrow
      // 05e: aload 3
      // 05f: ifnonnull 0c2
      // 062: aload 0
      // 063: getfield com/l7tech/policy/IncludeAssertionDereferenceTranslator.a Lcom/l7tech/objectmodel/GuidBasedEntityManager;
      // 066: aload 2
      // 067: invokevirtual com/l7tech/policy/assertion/Include.getPolicyGuid ()Ljava/lang/String;
      // 06a: invokeinterface com/l7tech/objectmodel/GuidBasedEntityManager.findByGuid (Ljava/lang/String;)Lcom/l7tech/objectmodel/GuidEntity; 2
      // 06f: checkcast com/l7tech/policy/Policy
      // 072: astore 3
      // 073: aload 3
      // 074: ifnonnull 09e
      // 077: new com/l7tech/policy/assertion/PolicyAssertionException
      // 07a: dup
      // 07b: aload 2
      // 07c: getstatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.e [Ljava/lang/String;
      // 07f: bipush 5
      // 080: aaload
      // 081: bipush 2
      // 082: anewarray 205
      // 085: dup
      // 086: bipush 0
      // 087: aload 2
      // 088: invokevirtual com/l7tech/policy/assertion/Include.getPolicyGuid ()Ljava/lang/String;
      // 08b: aastore
      // 08c: dup
      // 08d: bipush 1
      // 08e: aload 2
      // 08f: invokevirtual com/l7tech/policy/assertion/Include.getPolicyName ()Ljava/lang/String;
      // 092: aastore
      // 093: invokestatic java/text/MessageFormat.format (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
      // 096: invokespecial com/l7tech/policy/assertion/PolicyAssertionException.<init> (Lcom/l7tech/policy/assertion/Assertion;Ljava/lang/String;)V
      // 099: athrow
      // 09a: invokestatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 09d: athrow
      // 09e: goto 0c2
      // 0a1: astore 4
      // 0a3: new com/l7tech/policy/assertion/PolicyAssertionException
      // 0a6: dup
      // 0a7: aload 2
      // 0a8: aload 4
      // 0aa: invokestatic com/l7tech/util/ExceptionUtils.getMessage (Ljava/lang/Throwable;)Ljava/lang/String;
      // 0ad: getstatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.e [Ljava/lang/String;
      // 0b0: astore 6
      // 0b2: aload 6
      // 0b4: bipush 4
      // 0b5: aaload
      // 0b6: swap
      // 0b7: 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" ]
      // 0bc: aload 4
      // 0be: invokespecial com/l7tech/policy/assertion/PolicyAssertionException.<init> (Lcom/l7tech/policy/assertion/Assertion;Ljava/lang/String;Ljava/lang/Throwable;)V
      // 0c1: athrow
      // 0c2: aload 0
      // 0c3: getfield com/l7tech/policy/IncludeAssertionDereferenceTranslator.c Z
      // 0c6: ifeq 0ce
      // 0c9: aload 3
      // 0ca: invokevirtual com/l7tech/policy/Policy.getAssertion ()Lcom/l7tech/policy/assertion/Assertion;
      // 0cd: areturn
      // 0ce: new java/util/HashMap
      // 0d1: dup
      // 0d2: invokespecial java/util/HashMap.<init> ()V
      // 0d5: astore 4
      // 0d7: invokestatic com/l7tech/policy/wsp/WspReader.getDefault ()Lcom/l7tech/policy/wsp/WspReader;
      // 0da: aload 3
      // 0db: invokevirtual com/l7tech/policy/Policy.getAssertion ()Lcom/l7tech/policy/assertion/Assertion;
      // 0de: invokestatic com/l7tech/policy/wsp/WspWriter.getPolicyXml (Lcom/l7tech/policy/assertion/Assertion;)Ljava/lang/String;
      // 0e1: getstatic com/l7tech/policy/wsp/WspReader.INCLUDE_DISABLED Lcom/l7tech/policy/wsp/WspReader$Visibility;
      // 0e4: invokevirtual com/l7tech/policy/wsp/WspReader.parsePermissively (Ljava/lang/String;Lcom/l7tech/policy/wsp/WspReader$Visibility;)Lcom/l7tech/policy/assertion/Assertion;
      // 0e7: astore 5
      // 0e9: aload 2
      // 0ea: invokevirtual com/l7tech/policy/assertion/Include.retrieveFragmentPolicy ()Lcom/l7tech/policy/Policy;
      // 0ed: ifnull 10c
      // 0f0: aload 0
      // 0f1: aload 2
      // 0f2: invokevirtual com/l7tech/policy/assertion/Include.retrieveFragmentPolicy ()Lcom/l7tech/policy/Policy;
      // 0f5: invokevirtual com/l7tech/policy/Policy.getAssertion ()Lcom/l7tech/policy/assertion/Assertion;
      // 0f8: aload 4
      // 0fa: invokevirtual com/l7tech/policy/IncludeAssertionDereferenceTranslator.a (Lcom/l7tech/policy/assertion/Assertion;Ljava/util/HashMap;)V
      // 0fd: aload 0
      // 0fe: aload 5
      // 100: aload 4
      // 102: invokevirtual com/l7tech/policy/IncludeAssertionDereferenceTranslator.b (Lcom/l7tech/policy/assertion/Assertion;Ljava/util/HashMap;)V
      // 105: goto 10c
      // 108: invokestatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 10b: athrow
      // 10c: aload 5
      // 10e: areturn
      // 10f: astore 4
      // 111: new com/l7tech/policy/assertion/PolicyAssertionException
      // 114: dup
      // 115: aload 2
      // 116: aload 4
      // 118: invokestatic com/l7tech/util/ExceptionUtils.getMessage (Ljava/lang/Throwable;)Ljava/lang/String;
      // 11b: getstatic com/l7tech/policy/IncludeAssertionDereferenceTranslator.e [Ljava/lang/String;
      // 11e: bipush 1
      // 11f: aaload
      // 120: swap
      // 121: 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" ]
      // 126: aload 4
      // 128: invokespecial com/l7tech/policy/assertion/PolicyAssertionException.<init> (Lcom/l7tech/policy/assertion/Assertion;Ljava/lang/String;Ljava/lang/Throwable;)V
      // 12b: athrow
      // try (55 -> 78): 78 java/lang/Exception
      // try (26 -> 44): 44 java/lang/Exception
      // try (13 -> 21): 21 java/lang/Exception
      // try (10 -> 16): 17 java/lang/Exception
      // try (0 -> 5): 5 java/lang/Exception
      // try (48 -> 80): 81 java/lang/Exception
      // try (97 -> 102): 132 java/lang/Exception
      // try (114 -> 127): 128 java/lang/Exception
      // try (103 -> 131): 132 java/lang/Exception
   }

   @Override
   public void translationFinished(@Nullable Assertion var1) {
      try {
         if (!(var1 instanceof Include)) {
            return;
         }
      } catch (NullPointerException var2) {
         throw a(var2);
      }

      this.b.remove(((Include)var1).getPolicyGuid());
   }

   private void a(@Nullable Assertion var1, HashMap<String, Policy> var2) {
      if (var1 instanceof CompositeAssertion var3) {
         Iterator var4 = var3.children();

         while (var4.hasNext()) {
            Assertion var5 = (Assertion)var4.next();
            this.a(var5, var2);
         }
      } else if (var1 instanceof Include var7) {
         try {
            if (var7.retrieveFragmentPolicy() != null) {
               var2.put(var7.getPolicyGuid(), var7.retrieveFragmentPolicy());
            }
         } catch (NullPointerException var6) {
            throw a(var6);
         }
      }
   }

   private void b(@Nullable Assertion var1, HashMap<String, Policy> var2) {
      if (var1 instanceof CompositeAssertion var3) {
         Iterator var4 = var3.children();

         while (var4.hasNext()) {
            Assertion var5 = (Assertion)var4.next();
            this.b(var5, var2);
         }
      } else if (var1 instanceof Include var7) {
         try {
            if (var2.containsKey(var7.getPolicyGuid())) {
               var7.replaceFragmentPolicy((Policy)var2.get(var7.getPolicyGuid()));
            }
         } catch (NullPointerException var6) {
            throw a(var6);
         }
      }
   }

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

   static {
      String[] var5 = new String[6];
      int var3 = 0;
      String var2 = "^cg2Ib<o*e>Pg>d*|?_b(yo57S|}Mey8_w}> Hdt3Pk}ie5=So9=C{2P{9xn5!Sb4~s/q\u0018mey8_w\u001ax~a4N.4n*g4M{4ooq\u001ftdv=Ij8yZz=Um$Z\u007f|5O.4n*g4M{4ooq";
      int var4 = "^cg2Ib<o*e>Pg>d*|?_b(yo57S|}Mey8_w}> Hdt3Pk}ie5=So9=C{2P{9xn5!Sb4~s/q\u0018mey8_w\u001ax~a4N.4n*g4M{4ooq\u001ftdv=Ij8yZz=Um$Z\u007f|5O.4n*g4M{4ooq"
         .length();
      char var1 = '$';
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 101;
         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) {
                     e = var5;
                     return;
                  }

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

                  var2 = "\u007fSC\u0004g\\J^R\u0002\ndX\u000e\ntL\u0005gL\u000eOY\u0002\u0016dU\u0003ID\u0018FEcSA\n~]\u000f\n\\Q\u0015nK\u001eCRLFy\\\fOOQF\u007fVJzRN\u000fh@J\tF\u0012\u001b+\u0011\u0011\u001b@\u000bJ+N\u0002C^JFeVJFRL\u0001nKJOEK\u0015\u007fJ";
                  var4 = "\u007fSC\u0004g\\J^R\u0002\ndX\u000e\ntL\u0005gL\u000eOY\u0002\u0016dU\u0003ID\u0018FEcSA\n~]\u000f\n\\Q\u0015nK\u001eCRLFy\\\fOOQF\u007fVJzRN\u000fh@J\tF\u0012\u001b+\u0011\u0011\u001b@\u000bJ+N\u0002C^JFeVJFRL\u0001nKJOEK\u0015\u007fJ"
                     .length();
                  var1 = ' ';
                  var7 = -1;
            }

            var10000 = 82;
            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] ^ 56);
      }

      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 -> 120;
            case 1 -> 111;
            case 2 -> 112;
            case 3 -> 52;
            case 4 -> 89;
            case 5 -> 107;
            default -> 56;
         });
      }

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