package com.l7tech.server.identity.cert;

import com.l7tech.gateway.common.security.RevocationCheckPolicy;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectModelException;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.HibernateEntityManager;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

public class RevocationCheckPolicyManagerImpl extends HibernateEntityManager<RevocationCheckPolicy, EntityHeader> implements RevocationCheckPolicyManager {
   private static final String m;
   private final DetachedCriteria n;
   private static final String[] o;

   public RevocationCheckPolicyManagerImpl() {
      this.n = DetachedCriteria.forClass(this.getImpClass()).add(Restrictions.eq(o[2], Boolean.TRUE));
   }

   public Goid save(RevocationCheckPolicy var1) throws SaveException {
      Goid var2 = super.save(var1);

      try {
         this.updateDefault(var2, var1);
         return var2;
      } catch (ObjectModelException var4) {
         throw new SaveException(var4);
      }
   }

   public void update(RevocationCheckPolicy var1) throws UpdateException {
      super.update(var1);

      try {
         this.updateDefault(var1.getGoid(), var1);
      } catch (ObjectModelException var3) {
         throw new UpdateException(var3);
      }
   }

   public Class getImpClass() {
      return RevocationCheckPolicy.class;
   }

   @Override
   public Class getInterfaceClass() {
      return RevocationCheckPolicy.class;
   }

   @Override
   public String getTableName() {
      return o[1];
   }

   @Override
   public void updateDefault(Goid param1, RevocationCheckPolicy param2) throws FindException, UpdateException {
      // $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: invokevirtual com/l7tech/gateway/common/security/RevocationCheckPolicy.isDefaultPolicy ()Z
      // 04: ifeq 5b
      // 07: aload 0
      // 08: invokevirtual com/l7tech/server/identity/cert/RevocationCheckPolicyManagerImpl.findAll ()Ljava/util/Collection;
      // 0b: astore 3
      // 0c: aload 3
      // 0d: invokeinterface java/util/Collection.iterator ()Ljava/util/Iterator; 1
      // 12: astore 4
      // 14: aload 4
      // 16: invokeinterface java/util/Iterator.hasNext ()Z 1
      // 1b: ifeq 5b
      // 1e: aload 4
      // 20: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 25: checkcast com/l7tech/gateway/common/security/RevocationCheckPolicy
      // 28: astore 5
      // 2a: aload 5
      // 2c: invokevirtual com/l7tech/gateway/common/security/RevocationCheckPolicy.isDefaultPolicy ()Z
      // 2f: ifeq 58
      // 32: aload 5
      // 34: invokevirtual com/l7tech/gateway/common/security/RevocationCheckPolicy.getGoid ()Lcom/l7tech/objectmodel/Goid;
      // 37: aload 1
      // 38: invokevirtual com/l7tech/objectmodel/Goid.equals (Ljava/lang/Object;)Z
      // 3b: ifne 58
      // 3e: goto 45
      // 41: invokestatic com/l7tech/server/identity/cert/RevocationCheckPolicyManagerImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 44: athrow
      // 45: aload 5
      // 47: bipush 0
      // 48: invokevirtual com/l7tech/gateway/common/security/RevocationCheckPolicy.setDefaultPolicy (Z)V
      // 4b: aload 0
      // 4c: aload 5
      // 4e: invokevirtual com/l7tech/server/identity/cert/RevocationCheckPolicyManagerImpl.update (Lcom/l7tech/gateway/common/security/RevocationCheckPolicy;)V
      // 51: goto 58
      // 54: invokestatic com/l7tech/server/identity/cert/RevocationCheckPolicyManagerImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 57: athrow
      // 58: goto 14
      // 5b: return
      // try (16 -> 24): 25 com/l7tech/objectmodel/FindException
      // try (19 -> 33): 34 com/l7tech/objectmodel/FindException
   }

   @Override
   public RevocationCheckPolicy getDefaultPolicy() throws FindException {
      return (RevocationCheckPolicy)this.getHibernateTemplate().execute(new f(this));
   }

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

   static {
      String[] var5 = new String[3];
      int var3 = 0;
      String var2 = "U2p\u0003U2p\rC4f\u0001|Knw>l\tj^";
      int var4 = "U2p\u0003U2p\rC4f\u0001|Knw>l\tj^".length();
      char var1 = 3;
      int var0 = -1;

      while (true) {
         String var10002 = b(124, a(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            o = var5;
            m = o[0];
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

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

      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 -> 91;
            case 1 -> 45;
            case 2 -> 124;
            case 3 -> 28;
            case 4 -> 117;
            case 5 -> 91;
            default -> 102;
         });
      }

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