package com.l7tech.server.policy.assertion;

import com.l7tech.gateway.common.audit.AuditFactory;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.ResolveServiceAssertion;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.service.ServiceCache;
import jakarta.inject.Inject;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ServerResolveServiceAssertion extends AbstractServerAssertion<ResolveServiceAssertion> {
   @Inject
   ServiceCache serviceCache;
   private final String[] d;
   private static final String[] e;

   public ServerResolveServiceAssertion(@NotNull ResolveServiceAssertion var1) {
      if (var1 == null) {
         b(0);
      }

      this(var1, null);
   }

   public ServerResolveServiceAssertion(@NotNull ResolveServiceAssertion var1, @Nullable AuditFactory var2) {
      if (var1 == null) {
         b(1);
      }

      super(var1, var2);
      this.d = var1.getVariablesUsed();
   }

   @Override
   public AssertionStatus checkRequest(PolicyEnforcementContext param1) throws IOException, 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: aload 0
      // 002: getfield com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.d [Ljava/lang/String;
      // 005: aload 0
      // 006: invokevirtual com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 009: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.getVariableMap ([Ljava/lang/String;Lcom/l7tech/gateway/common/audit/Audit;)Ljava/util/Map; 3
      // 00e: astore 2
      // 00f: aload 0
      // 010: getfield com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 013: checkcast com/l7tech/policy/assertion/ResolveServiceAssertion
      // 016: invokevirtual com/l7tech/policy/assertion/ResolveServiceAssertion.getPrefix ()Ljava/lang/String;
      // 019: astore 3
      // 01a: aconst_null
      // 01b: aload 3
      // 01c: if_acmpeq 02d
      // 01f: aload 3
      // 020: invokevirtual java/lang/String.isEmpty ()Z
      // 023: ifeq 03c
      // 026: goto 02d
      // 029: invokestatic com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 02c: athrow
      // 02d: aload 0
      // 02e: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RESOLVE_SERVICE_NO_PREFIX Lcom/l7tech/gateway/common/audit/Messages$M;
      // 031: invokevirtual com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;)V
      // 034: getstatic com/l7tech/policy/assertion/AssertionStatus.FAILED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 037: areturn
      // 038: invokestatic com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 03b: athrow
      // 03c: aload 0
      // 03d: getfield com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.serviceCache Lcom/l7tech/server/service/ServiceCache;
      // 040: aload 0
      // 041: getfield com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 044: checkcast com/l7tech/policy/assertion/ResolveServiceAssertion
      // 047: invokevirtual com/l7tech/policy/assertion/ResolveServiceAssertion.getUri ()Ljava/lang/String;
      // 04a: aload 2
      // 04b: aload 0
      // 04c: invokevirtual com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 04f: invokestatic com/l7tech/server/policy/variable/ExpandVariables.process (Ljava/lang/String;Ljava/util/Map;Lcom/l7tech/gateway/common/audit/Audit;)Ljava/lang/String;
      // 052: aconst_null
      // 053: aconst_null
      // 054: invokevirtual com/l7tech/server/service/ServiceCache.resolve (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/util/Collection;
      // 057: astore 5
      // 059: aload 5
      // 05b: ifnull 06f
      // 05e: aload 5
      // 060: invokeinterface java/util/Collection.isEmpty ()Z 1
      // 065: ifeq 07f
      // 068: goto 06f
      // 06b: invokestatic com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 06e: athrow
      // 06f: aload 0
      // 070: invokevirtual com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 073: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RESOLVE_SERVICE_NOT_FOUND Lcom/l7tech/gateway/common/audit/Messages$M;
      // 076: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;)V 2
      // 07b: getstatic com/l7tech/policy/assertion/AssertionStatus.FAILED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 07e: areturn
      // 07f: aload 5
      // 081: invokeinterface java/util/Collection.size ()I 1
      // 086: bipush 1
      // 087: if_icmple 09e
      // 08a: aload 0
      // 08b: invokevirtual com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 08e: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RESOLVE_SERVICE_FOUND_MULTI Lcom/l7tech/gateway/common/audit/Messages$M;
      // 091: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;)V 2
      // 096: getstatic com/l7tech/policy/assertion/AssertionStatus.FAILED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 099: areturn
      // 09a: invokestatic com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 09d: athrow
      // 09e: aload 5
      // 0a0: invokeinterface java/util/Collection.iterator ()Ljava/util/Iterator; 1
      // 0a5: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 0aa: checkcast com/l7tech/gateway/common/service/PublishedService
      // 0ad: astore 4
      // 0af: goto 0d2
      // 0b2: astore 5
      // 0b4: aload 0
      // 0b5: invokevirtual com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 0b8: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RESOLVE_SERVICE_FAILED Lcom/l7tech/gateway/common/audit/Messages$M;
      // 0bb: bipush 1
      // 0bc: anewarray 276
      // 0bf: dup
      // 0c0: bipush 0
      // 0c1: aload 5
      // 0c3: invokestatic com/l7tech/util/ExceptionUtils.getMessage (Ljava/lang/Throwable;)Ljava/lang/String;
      // 0c6: aastore
      // 0c7: aload 5
      // 0c9: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;Ljava/lang/Throwable;)V 4
      // 0ce: getstatic com/l7tech/policy/assertion/AssertionStatus.FAILED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0d1: areturn
      // 0d2: aload 4
      // 0d4: invokevirtual com/l7tech/gateway/common/service/PublishedService.getGoid ()Lcom/l7tech/objectmodel/Goid;
      // 0d7: astore 5
      // 0d9: aload 1
      // 0da: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.getRequest ()Lcom/l7tech/message/Message; 1
      // 0df: ldc com/l7tech/message/HasServiceId
      // 0e1: invokevirtual com/l7tech/message/Message.getKnob (Ljava/lang/Class;)Ljava/lang/Object;
      // 0e4: ifnonnull 102
      // 0e7: aload 1
      // 0e8: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.getRequest ()Lcom/l7tech/message/Message; 1
      // 0ed: ldc com/l7tech/message/HasServiceId
      // 0ef: new com/l7tech/message/HasServiceIdImpl
      // 0f2: dup
      // 0f3: aload 5
      // 0f5: invokespecial com/l7tech/message/HasServiceIdImpl.<init> (Lcom/l7tech/objectmodel/Goid;)V
      // 0f8: invokevirtual com/l7tech/message/Message.attachKnob (Ljava/lang/Class;Lcom/l7tech/message/MessageKnob;)V
      // 0fb: goto 102
      // 0fe: invokestatic com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 101: athrow
      // 102: aload 0
      // 103: invokevirtual com/l7tech/server/policy/assertion/ServerResolveServiceAssertion.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 106: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RESOLVE_SERVICE_SUCCEEDED Lcom/l7tech/gateway/common/audit/Messages$M;
      // 109: bipush 1
      // 10a: anewarray 276
      // 10d: dup
      // 10e: bipush 0
      // 10f: aload 5
      // 111: invokevirtual com/l7tech/objectmodel/Goid.toString ()Ljava/lang/String;
      // 114: aastore
      // 115: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V 3
      // 11a: aload 1
      // 11b: aload 3
      // 11c: getstatic com/l7tech/policy/assertion/ResolveServiceAssertion.OID_SUFFIX Ljava/lang/String;
      // 11f: 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" ]
      // 124: aload 5
      // 126: invokevirtual com/l7tech/objectmodel/Goid.toString ()Ljava/lang/String;
      // 129: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 12e: aload 1
      // 12f: aload 3
      // 130: getstatic com/l7tech/policy/assertion/ResolveServiceAssertion.NAME_SUFFIX Ljava/lang/String;
      // 133: 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" ]
      // 138: aload 4
      // 13a: invokevirtual com/l7tech/gateway/common/service/PublishedService.getName ()Ljava/lang/String;
      // 13d: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 142: aload 1
      // 143: aload 3
      // 144: getstatic com/l7tech/policy/assertion/ResolveServiceAssertion.SOAP_SUFFIX Ljava/lang/String;
      // 147: 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" ]
      // 14c: aload 4
      // 14e: invokevirtual com/l7tech/gateway/common/service/PublishedService.isSoap ()Z
      // 151: invokestatic java/lang/Boolean.valueOf (Z)Ljava/lang/Boolean;
      // 154: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 159: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 15c: areturn
      // try (42 -> 47): 48 com/l7tech/server/service/resolution/ServiceResolutionException
      // try (15 -> 26): 26 com/l7tech/server/service/resolution/ServiceResolutionException
      // try (12 -> 18): 19 com/l7tech/server/service/resolution/ServiceResolutionException
      // try (28 -> 55): 74 com/l7tech/server/service/resolution/ServiceResolutionException
      // try (56 -> 65): 74 com/l7tech/server/service/resolution/ServiceResolutionException
      // try (56 -> 66): 66 java/io/IOException
      // try (68 -> 73): 74 com/l7tech/server/service/resolution/ServiceResolutionException
      // try (92 -> 105): 106 com/l7tech/server/service/resolution/ServiceResolutionException
   }

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

   static {
      String[] var5 = new String[4];
      int var3 = 0;
      String var2 = "\u001f9C>\u007fq\u0017\u0011$@\u001d%]ta2\n\u001b)Xt~`\f\b/Bt}j\u0012\u0017)Itlv\r\u001b8D2bkQ-/B-hw,\u001b9_7{`-\u001b8F2n`?\r9U)yl\u0011\u0010";
      int var4 = "\u001f9C>\u007fq\u0017\u0011$@\u001d%]ta2\n\u001b)Xt~`\f\b/Bt}j\u0012\u0017)Itlv\r\u001b8D2bkQ-/B-hw,\u001b9_7{`-\u001b8F2n`?\r9U)yl\u0011\u0010"
         .length();
      char var1 = '\t';
      int var7 = -1;

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

         while (true) {
            String var8 = b(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 = "Z;F*a#>' O6xx\b\u0012rN,g=&(=\\\r`q\nF\"I1tp\u0003\u00127Zc28\u0015ArG%58\u0015Hw[cxh\u0015\u0012rF,a=\u0004\u0003rF6yq";
                  var4 = "Z;F*a#>' O6xx\b\u0012rN,g=&(=\\\r`q\nF\"I1tp\u0003\u00127Zc28\u0015ArG%58\u0015Hw[cxh\u0015\u0012rF,a=\u0004\u0003rF6yq".length();
                  var1 = 6;
                  var7 = -1;
            }

            var10000 = 41;
            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] ^ 79);
      }

      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 -> 79;
            case 1 -> 123;
            case 2 -> 1;
            case 3 -> 106;
            case 4 -> 60;
            case 5 -> 52;
            default -> 79;
         });
      }

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