package com.l7tech.external.assertions.gatewaygraphql.server.resolver.helper;

import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.gateway.common.service.ServiceDocument;
import com.l7tech.objectmodel.ObjectModelException;
import com.l7tech.server.service.ServiceDocumentManager;
import com.l7tech.util.ExceptionUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.BeanFactory;

public class ServiceDocumentHelper {
   private static final Logger a;
   private final ServiceDocumentManager b;
   private static final String[] c;

   public ServiceDocumentHelper(BeanFactory var1) {
      this.b = (ServiceDocumentManager)var1.getBean(c[0], ServiceDocumentManager.class);
   }

   public Collection<ServiceDocument> getDocumentsOf(PublishedService var1) {
      try {
         return this.b.findByServiceId(var1.getGoid());
      } catch (Exception var3) {
         a.log(Level.WARNING, c[1], new Object[]{var1.getGoid(), var1.getName(), ExceptionUtils.getMessageWithCause(var3)});
         return Collections.emptyList();
      }
   }

   public void clearDocumentsFor(PublishedService var1) throws ObjectModelException {
      for (ServiceDocument var4 : this.getDocumentsOf(var1)) {
         this.b.delete(var4);
      }
   }

   public void setDocumentsFor(PublishedService param1, Collection<ServiceDocument> param2) throws ObjectModelException {
      // $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: ifnull 14
      // 04: aload 2
      // 05: invokeinterface java/util/Collection.isEmpty ()Z 1
      // 0a: ifeq 19
      // 0d: goto 14
      // 10: invokestatic com/l7tech/external/assertions/gatewaygraphql/server/resolver/helper/ServiceDocumentHelper.a (Lcom/l7tech/objectmodel/ObjectModelException;)Lcom/l7tech/objectmodel/ObjectModelException;
      // 13: athrow
      // 14: return
      // 15: invokestatic com/l7tech/external/assertions/gatewaygraphql/server/resolver/helper/ServiceDocumentHelper.a (Lcom/l7tech/objectmodel/ObjectModelException;)Lcom/l7tech/objectmodel/ObjectModelException;
      // 18: athrow
      // 19: aload 2
      // 1a: invokeinterface java/util/Collection.iterator ()Ljava/util/Iterator; 1
      // 1f: astore 3
      // 20: aload 3
      // 21: invokeinterface java/util/Iterator.hasNext ()Z 1
      // 26: ifeq 54
      // 29: aload 3
      // 2a: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 2f: checkcast com/l7tech/gateway/common/service/ServiceDocument
      // 32: astore 4
      // 34: aload 4
      // 36: getstatic com/l7tech/gateway/common/service/ServiceDocument.DEFAULT_GOID Lcom/l7tech/objectmodel/Goid;
      // 39: invokevirtual com/l7tech/gateway/common/service/ServiceDocument.setGoid (Lcom/l7tech/objectmodel/Goid;)V
      // 3c: aload 4
      // 3e: aload 1
      // 3f: invokevirtual com/l7tech/gateway/common/service/PublishedService.getGoid ()Lcom/l7tech/objectmodel/Goid;
      // 42: invokevirtual com/l7tech/gateway/common/service/ServiceDocument.setServiceId (Lcom/l7tech/objectmodel/Goid;)V
      // 45: aload 0
      // 46: getfield com/l7tech/external/assertions/gatewaygraphql/server/resolver/helper/ServiceDocumentHelper.b Lcom/l7tech/server/service/ServiceDocumentManager;
      // 49: aload 4
      // 4b: invokeinterface com/l7tech/server/service/ServiceDocumentManager.save (Lcom/l7tech/objectmodel/PersistentEntity;)Lcom/l7tech/objectmodel/Goid; 2
      // 50: pop
      // 51: goto 20
      // 54: return
      // try (0 -> 5): 6 com/l7tech/objectmodel/ObjectModelException
      // try (2 -> 9): 9 com/l7tech/objectmodel/ObjectModelException
   }

   static {
      String[] var5 = new String[2];
      int var3 = 0;
      String var2 = "dtF\u001eu/]S~W\u001dq)Vc\\U\u0006}+]e@Qp]\u0004y(\u0018c~\u0014\u001ay8J~tB\r<>]d~A\u001a\u007f)K7w[\u001a<8Pr1G\rn:Qtt\u000eHg|E8j\u0005\u00150l[vdG\r!7\nj";
      int var4 = "dtF\u001eu/]S~W\u001dq)Vc\\U\u0006}+]e@Qp]\u0004y(\u0018c~\u0014\u001ay8J~tB\r<>]d~A\u001a\u007f)K7w[\u001a<8Pr1G\rn:Qtt\u000eHg|E8j\u0005\u00150l[vdG\r!7\nj"
         .length();
      char var1 = 22;
      int var0 = -1;

      while (true) {
         String var10002 = a(1, a(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            c = var5;
            a = Logger.getLogger(ServiceDocumentHelper.class.getName());
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

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

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

      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 -> 22;
            case 1 -> 16;
            case 2 -> 53;
            case 3 -> 105;
            case 4 -> 29;
            case 5 -> 77;
            default -> 57;
         });
      }

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