package com.l7tech.external.assertions.gatewaymanagement.server;

import com.l7tech.gateway.api.ManagedObject;
import com.l7tech.gateway.common.security.rbac.OperationType;
import com.l7tech.gateway.common.security.rbac.PermissionDeniedException;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityManager;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectModelException;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.server.security.rbac.RbacServices;
import com.l7tech.server.security.rbac.SecurityFilter;
import com.l7tech.util.Eithers;
import com.l7tech.util.Functions;
import com.l7tech.util.GoidUpgradeMapper;
import com.l7tech.util.Option;
import com.l7tech.util.Functions.UnaryThrows;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.transaction.PlatformTransactionManager;

public abstract class EntityManagerResourceFactory<R, E extends PersistentEntity, EH extends EntityHeader>
   extends ResourceFactorySupport<R, E>
   implements ResourceFactory<R, E> {
   protected static final int VERSION_NOT_PRESENT = Integer.MIN_VALUE;
   static final String g;
   static final String h;
   static final String i;
   static final String j;
   private final boolean k;
   private final boolean l;
   private final boolean m;
   private final EntityManager<E, EH> n;
   private static final String[] y;

   @Override
   public final EntityType getType() {
      return EntityType.findTypeByEntity(this.n.getImpClass());
   }

   @Override
   public boolean isReadOnly() {
      return this.k;
   }

   @Override
   public Set<String> getSelectors() {
      String[] var10002 = new String[2];
      String[] var2 = y;
      var10002[0] = var2[22];
      var10002[1] = var2[21];
      HashSet var1 = new HashSet<>(Arrays.asList(var10002));

      try {
         if (this.l) {
            var1.add(var2[18]);
         }
      } catch (PermissionDeniedException var3) {
         throw d(var3);
      }

      try {
         if (this.m) {
            var1.add(y[6]);
         }
      } catch (PermissionDeniedException var4) {
         throw d(var4);
      }

      var1.addAll(this.getCustomSelectors());
      return Collections.unmodifiableSet(var1);
   }

   @Override
   public Map<String, String> createResource(Object var1) throws ResourceFactory.InvalidResourceException {
      return this.createResource(null, var1);
   }

   @Override
   public Map<String, String> createResource(@Nullable String var1, Object var2) throws ResourceFactory.InvalidResourceException {
      this.a();
      Goid var3 = (Goid)Eithers.extract(this.transactional(new ah(this, var2, var1), false));
      return Collections.singletonMap(y[22], var3.toString());
   }

   protected Goid doSaveEntity(E var1) throws SaveException {
      return this.n.save(var1);
   }

   protected void doSaveEntity(Goid var1, E var2) throws SaveException {
      this.n.save(var1, var2);
   }

   @Override
   public R getResource(Map<String, String> var1) throws ResourceFactory.ResourceNotFoundException {
      return (R)Eithers.extract(this.transactional(new ai(this, var1), true));
   }

   @Override
   public Collection<Map<String, String>> getResources() {
      List var1 = Collections.emptyList();

      try {
         List var2 = new ArrayList(this.n.findAllHeaders());
         var2 = this.accessFilter(var2, this.n.getEntityType(), OperationType.READ, null);
         var2 = this.filterHeaders(var2);
         var1 = new ArrayList(var2.size());

         for (EntityHeader var4 : var2) {
            var1.add(Collections.singletonMap(y[22], var4.getStrId()));
         }
      } catch (FindException var5) {
         this.handleObjectModelException(var5);
      }

      return var1;
   }

   @Override
   public List<R> getResources(String var1, Boolean var2, Map<String, List<Object>> var3) {
      try {
         List var4 = this.n.findPagedMatching(0, -1, var1, var2, var3);
         var4 = this.accessFilter(var4, this.n.getEntityType(), OperationType.READ, null);
         var4 = this.filterEntities(var4);
         return Functions.map(var4, new aj(this));
      } catch (ObjectModelException var5) {
         this.handleObjectModelException(var5);
         return Collections.emptyList();
      }
   }

   @Override
   public boolean resourceExists(Map<String, String> var1) {
      return this.transactional(new ak(this, var1), true);
   }

   @Override
   public R putResource(Map<String, String> var1, Object var2) throws ResourceFactory.ResourceNotFoundException, ResourceFactory.InvalidResourceException {
      this.a();
      String var3 = (String)Eithers.extract2(this.transactional(new al(this, var1, var2), false));

      try {
         return this.getResource(Collections.singletonMap(y[22], var3));
      } catch (PermissionDeniedException var5) {
         return null;
      }
   }

   @Override
   public String deleteResource(Map<String, String> var1) throws ResourceFactory.ResourceNotFoundException {
      this.a();
      return (String)Eithers.extract(this.transactional(new am(this, var1), false));
   }

   public R asResource(E var1) {
      throw new ResourceFactory.ResourceAccessException(y[2]);
   }

   protected R asResource(EntityManagerResourceFactory.EntityBag<E> var1) {
      return this.asResource((E)var1.getEntity());
   }

   public E fromResource(Object var1, boolean var2) throws ResourceFactory.InvalidResourceException {
      throw new ResourceFactory.InvalidResourceException(ResourceFactory.InvalidResourceException.ExceptionType.UNEXPECTED_TYPE, y[23]);
   }

   public EntityManagerResourceFactory.EntityBag<E> fromResourceAsBag(Object var1) throws ResourceFactory.InvalidResourceException {
      return this.fromResourceAsBag(var1, true);
   }

   public EntityManagerResourceFactory.EntityBag<E> fromResourceAsBag(Object var1, boolean var2) throws ResourceFactory.InvalidResourceException {
      return new EntityManagerResourceFactory.EntityBag<>(this.fromResource(var1, var2));
   }

   public final R identify(R var1, E var2) {
      return this.identify((R)var1, var2.getId(), var2.getVersion());
   }

   protected final R identify(R var1, String var2, int var3) {
      if (var1 instanceof ManagedObject var4) {
         var4.setId(var2);
         var4.setVersion(var3);
      }

      return (R)var1;
   }

   protected List<EH> filterHeaders(List<EH> var1) {
      return var1;
   }

   protected List<E> filterEntities(List<E> var1) {
      return Functions.grep(var1, new an(this));
   }

   protected E filterEntity(E var1) {
      return (E)var1;
   }

   @NotNull
   protected final String getRequiredSelector(@NotNull Map<String, String> var1, @NotNull String var2) throws ResourceFactory.InvalidResourceSelectors {
      try {
         if (var1 == null) {
            b(0);
         }
      } catch (ResourceFactory.InvalidResourceSelectors var5) {
         throw d(var5);
      }

      try {
         if (var2 == null) {
            b(1);
         }
      } catch (ResourceFactory.InvalidResourceSelectors var7) {
         throw d(var7);
      }

      Option var3 = Option.optional((String)var1.get(var2));

      try {
         if (!var3.isSome()) {
            throw new ResourceFactory.InvalidResourceSelectors();
         }
      } catch (ResourceFactory.InvalidResourceSelectors var6) {
         throw d(var6);
      }

      try {
         String var10000 = (String)var3.some();
         if (var10000 == null) {
            b(2);
         }

         return var10000;
      } catch (ResourceFactory.InvalidResourceSelectors var4) {
         throw d(var4);
      }
   }

   @NotNull
   protected final E selectEntity(Map<String, String> param1) throws ResourceFactory.ResourceNotFoundException {
      // $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: aconst_null
      // 001: astore 2
      // 002: aload 1
      // 003: getstatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.y [Ljava/lang/String;
      // 006: astore 9
      // 008: aload 9
      // 00a: bipush 17
      // 00c: aaload
      // 00d: invokeinterface java/util/Map.get (Ljava/lang/Object;)Ljava/lang/Object; 2
      // 012: checkcast java/lang/String
      // 015: astore 3
      // 016: aload 1
      // 017: aload 9
      // 019: bipush 5
      // 01a: aaload
      // 01b: invokeinterface java/util/Map.get (Ljava/lang/Object;)Ljava/lang/Object; 2
      // 020: checkcast java/lang/String
      // 023: astore 4
      // 025: aload 1
      // 026: aload 9
      // 028: bipush 1
      // 029: aaload
      // 02a: invokeinterface java/util/Map.get (Ljava/lang/Object;)Ljava/lang/Object; 2
      // 02f: checkcast java/lang/String
      // 032: astore 5
      // 034: aload 1
      // 035: aload 9
      // 037: bipush 26
      // 039: aaload
      // 03a: invokeinterface java/util/Map.get (Ljava/lang/Object;)Ljava/lang/Object; 2
      // 03f: checkcast java/lang/String
      // 042: astore 6
      // 044: aload 3
      // 045: ifnonnull 06c
      // 048: aload 4
      // 04a: ifnonnull 06c
      // 04d: goto 054
      // 050: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 053: athrow
      // 054: aload 6
      // 056: ifnonnull 06c
      // 059: goto 060
      // 05c: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 05f: athrow
      // 060: new com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceSelectors
      // 063: dup
      // 064: invokespecial com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceSelectors.<init> ()V
      // 067: athrow
      // 068: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 06b: athrow
      // 06c: aload 3
      // 06d: ifnull 08a
      // 070: aload 0
      // 071: getfield com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.n Lcom/l7tech/objectmodel/EntityManager;
      // 074: aload 0
      // 075: aload 3
      // 076: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.toInternalId (Ljava/lang/String;)Lcom/l7tech/objectmodel/Goid;
      // 079: invokeinterface com/l7tech/objectmodel/EntityManager.findByPrimaryKey (Lcom/l7tech/objectmodel/Goid;)Lcom/l7tech/objectmodel/PersistentEntity; 2
      // 07e: astore 2
      // 07f: goto 08a
      // 082: astore 7
      // 084: aload 0
      // 085: aload 7
      // 087: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.handleObjectModelException (Lcom/l7tech/objectmodel/ObjectModelException;)V
      // 08a: aload 2
      // 08b: ifnonnull 0bf
      // 08e: aload 0
      // 08f: getfield com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.l Z
      // 092: ifeq 0bf
      // 095: goto 09c
      // 098: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 09b: athrow
      // 09c: aload 4
      // 09e: ifnull 0bf
      // 0a1: goto 0a8
      // 0a4: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0a7: athrow
      // 0a8: aload 0
      // 0a9: getfield com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.n Lcom/l7tech/objectmodel/EntityManager;
      // 0ac: aload 4
      // 0ae: invokeinterface com/l7tech/objectmodel/EntityManager.findByUniqueName (Ljava/lang/String;)Lcom/l7tech/objectmodel/PersistentEntity; 2
      // 0b3: astore 2
      // 0b4: goto 0bf
      // 0b7: astore 7
      // 0b9: aload 0
      // 0ba: aload 7
      // 0bc: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.handleObjectModelException (Lcom/l7tech/objectmodel/ObjectModelException;)V
      // 0bf: aload 2
      // 0c0: ifnonnull 101
      // 0c3: aload 6
      // 0c5: ifnull 101
      // 0c8: goto 0cf
      // 0cb: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0ce: athrow
      // 0cf: aload 0
      // 0d0: getfield com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.n Lcom/l7tech/objectmodel/EntityManager;
      // 0d3: instanceof com/l7tech/objectmodel/GuidBasedEntityManager
      // 0d6: ifeq 101
      // 0d9: goto 0e0
      // 0dc: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0df: athrow
      // 0e0: aload 0
      // 0e1: getfield com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.n Lcom/l7tech/objectmodel/EntityManager;
      // 0e4: checkcast com/l7tech/objectmodel/GuidBasedEntityManager
      // 0e7: astore 7
      // 0e9: aload 7
      // 0eb: aload 6
      // 0ed: invokeinterface com/l7tech/objectmodel/GuidBasedEntityManager.findByGuid (Ljava/lang/String;)Lcom/l7tech/objectmodel/GuidEntity; 2
      // 0f2: checkcast com/l7tech/objectmodel/PersistentEntity
      // 0f5: astore 2
      // 0f6: goto 101
      // 0f9: astore 8
      // 0fb: aload 0
      // 0fc: aload 8
      // 0fe: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.handleObjectModelException (Lcom/l7tech/objectmodel/ObjectModelException;)V
      // 101: aload 2
      // 102: ifnonnull 10b
      // 105: aload 0
      // 106: aload 1
      // 107: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.selectEntityCustom (Ljava/util/Map;)Lcom/l7tech/objectmodel/PersistentEntity;
      // 10a: astore 2
      // 10b: aload 2
      // 10c: ifnull 1b2
      // 10f: aload 3
      // 110: ifnull 133
      // 113: goto 11a
      // 116: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 119: athrow
      // 11a: aload 3
      // 11b: aload 2
      // 11c: invokeinterface com/l7tech/objectmodel/PersistentEntity.getId ()Ljava/lang/String; 1
      // 121: invokevirtual java/lang/String.equalsIgnoreCase (Ljava/lang/String;)Z
      // 124: ifne 133
      // 127: goto 12e
      // 12a: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 12d: athrow
      // 12e: aconst_null
      // 12f: astore 2
      // 130: goto 1b2
      // 133: aload 4
      // 135: ifnull 163
      // 138: aload 2
      // 139: instanceof com/l7tech/objectmodel/NamedEntity
      // 13c: ifeq 163
      // 13f: goto 146
      // 142: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 145: athrow
      // 146: aload 4
      // 148: aload 2
      // 149: checkcast com/l7tech/objectmodel/NamedEntity
      // 14c: invokeinterface com/l7tech/objectmodel/NamedEntity.getName ()Ljava/lang/String; 1
      // 151: invokevirtual java/lang/String.equalsIgnoreCase (Ljava/lang/String;)Z
      // 154: ifne 163
      // 157: goto 15e
      // 15a: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 15d: athrow
      // 15e: aconst_null
      // 15f: astore 2
      // 160: goto 1b2
      // 163: aload 5
      // 165: ifnull 185
      // 168: aload 5
      // 16a: aload 2
      // 16b: invokeinterface com/l7tech/objectmodel/PersistentEntity.getVersion ()I 1
      // 170: invokestatic java/lang/Integer.toString (I)Ljava/lang/String;
      // 173: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 176: ifne 185
      // 179: goto 180
      // 17c: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 17f: athrow
      // 180: aconst_null
      // 181: astore 2
      // 182: goto 1b2
      // 185: aload 6
      // 187: ifnull 1b2
      // 18a: aload 2
      // 18b: instanceof com/l7tech/objectmodel/GuidEntity
      // 18e: ifeq 1b2
      // 191: goto 198
      // 194: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 197: athrow
      // 198: aload 6
      // 19a: aload 2
      // 19b: checkcast com/l7tech/objectmodel/GuidEntity
      // 19e: invokeinterface com/l7tech/objectmodel/GuidEntity.getGuid ()Ljava/lang/String; 1
      // 1a3: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 1a6: ifne 1b2
      // 1a9: goto 1b0
      // 1ac: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1af: athrow
      // 1b0: aconst_null
      // 1b1: astore 2
      // 1b2: aload 2
      // 1b3: ifnull 1bc
      // 1b6: aload 0
      // 1b7: aload 2
      // 1b8: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.filterEntity (Lcom/l7tech/objectmodel/PersistentEntity;)Lcom/l7tech/objectmodel/PersistentEntity;
      // 1bb: astore 2
      // 1bc: aload 2
      // 1bd: ifnonnull 1db
      // 1c0: new com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$ResourceNotFoundException
      // 1c3: dup
      // 1c4: aload 1
      // 1c5: invokestatic java/lang/String.valueOf (Ljava/lang/Object;)Ljava/lang/String;
      // 1c8: getstatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.y [Ljava/lang/String;
      // 1cb: bipush 0
      // 1cc: aaload
      // 1cd: swap
      // 1ce: 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" ]
      // 1d3: invokespecial com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$ResourceNotFoundException.<init> (Ljava/lang/String;)V
      // 1d6: athrow
      // 1d7: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1da: athrow
      // 1db: aload 0
      // 1dc: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.getType ()Lcom/l7tech/objectmodel/EntityType;
      // 1df: aload 2
      // 1e0: invokeinterface com/l7tech/objectmodel/PersistentEntity.getId ()Ljava/lang/String; 1
      // 1e5: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/ac.setEntityInfo (Lcom/l7tech/objectmodel/EntityType;Ljava/lang/String;)V
      // 1e8: aload 2
      // 1e9: dup
      // 1ea: ifnonnull 1f8
      // 1ed: bipush 3
      // 1ee: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.b (I)V
      // 1f1: goto 1f8
      // 1f4: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1f7: athrow
      // 1f8: areturn
      // try (39 -> 48): 48 com/l7tech/objectmodel/FindException
      // try (34 -> 41): 42 com/l7tech/objectmodel/FindException
      // try (32 -> 36): 37 com/l7tech/objectmodel/FindException
      // try (52 -> 59): 60 com/l7tech/objectmodel/FindException
      // try (66 -> 74): 75 com/l7tech/objectmodel/FindException
      // try (64 -> 69): 70 com/l7tech/objectmodel/FindException
      // try (77 -> 82): 83 com/l7tech/objectmodel/FindException
      // try (89 -> 98): 99 com/l7tech/objectmodel/FindException
      // try (87 -> 91): 92 com/l7tech/objectmodel/FindException
      // try (105 -> 110): 111 com/l7tech/objectmodel/FindException
      // try (121 -> 125): 126 com/l7tech/objectmodel/FindException
      // try (123 -> 133): 134 com/l7tech/objectmodel/FindException
      // try (139 -> 144): 145 com/l7tech/objectmodel/FindException
      // try (141 -> 153): 154 com/l7tech/objectmodel/FindException
      // try (159 -> 167): 168 com/l7tech/objectmodel/FindException
      // try (173 -> 178): 179 com/l7tech/objectmodel/FindException
      // try (175 -> 187): 188 com/l7tech/objectmodel/FindException
      // try (198 -> 211): 211 com/l7tech/objectmodel/FindException
      // try (213 -> 223): 224 com/l7tech/objectmodel/FindException
   }

   protected Set<String> getCustomSelectors() {
      return Collections.emptySet();
   }

   @Nullable
   protected E selectEntityCustom(Map<String, String> var1) throws ResourceFactory.ResourceAccessException, ResourceFactory.InvalidResourceSelectors {
      return null;
   }

   protected final EntityManagerResourceFactory.EntityBag<E> selectEntityBag(Map<String, String> var1) throws ResourceFactory.ResourceNotFoundException, ObjectModelException {
      return this.loadEntityBag(this.selectEntity(var1));
   }

   protected EntityManagerResourceFactory.EntityBag<E> loadEntityBag(E var1) throws ObjectModelException {
      return new EntityManagerResourceFactory.EntityBag<>((E)var1);
   }

   protected void updateEntity(E var1, E var2) throws ResourceFactory.InvalidResourceException {
      throw new ResourceFactory.InvalidResourceException(ResourceFactory.InvalidResourceException.ExceptionType.UNEXPECTED_TYPE, y[16]);
   }

   protected void updateEntityBag(EntityManagerResourceFactory.EntityBag<E> var1, EntityManagerResourceFactory.EntityBag<E> var2) throws ResourceFactory.InvalidResourceException {
      this.updateEntity((E)var1.getEntity(), (E)var2.getEntity());
   }

   protected void beforeCreateEntity(EntityManagerResourceFactory.EntityBag<E> var1) throws ObjectModelException {
   }

   protected void afterCreateEntity(EntityManagerResourceFactory.EntityBag<E> var1, Goid var2) throws ObjectModelException {
   }

   protected void beforeUpdateEntity(EntityManagerResourceFactory.EntityBag<E> var1) throws ObjectModelException {
   }

   protected void afterUpdateEntity(EntityManagerResourceFactory.EntityBag<E> var1) throws ObjectModelException {
   }

   protected void beforeDeleteEntity(EntityManagerResourceFactory.EntityBag<E> var1) throws ObjectModelException {
   }

   protected void afterDeleteEntity(EntityManagerResourceFactory.EntityBag<E> var1) throws ObjectModelException {
   }

   protected final Goid toInternalId(String var1) throws ResourceFactory.InvalidResourceSelectors {
      try {
         if (var1 == null) {
            throw new ResourceFactory.InvalidResourceSelectors();
         }
      } catch (IllegalArgumentException var4) {
         throw d(var4);
      }

      try {
         return new Goid(var1);
      } catch (IllegalArgumentException var3) {
         throw new ResourceFactory.InvalidResourceSelectors();
      }
   }

   protected final Goid toInternalId(EntityType var1, String var2, String var3) throws ResourceFactory.InvalidResourceException {
      try {
         if (var2 == null) {
            throw new ResourceFactory.InvalidResourceException(ResourceFactory.InvalidResourceException.ExceptionType.MISSING_VALUES, y[12] + var3);
         }
      } catch (IllegalArgumentException var6) {
         throw d(var6);
      }

      try {
         return GoidUpgradeMapper.mapId(var1, var2);
      } catch (IllegalArgumentException var5) {
         throw new ResourceFactory.InvalidResourceException(ResourceFactory.InvalidResourceException.ExceptionType.INVALID_VALUES, y[13] + var3);
      }
   }

   protected final void setIdentifier(PersistentEntity var1, String var2) throws ResourceFactory.InvalidResourceException {
      this.setIdentifier(var1, var2, true);
   }

   protected final void setIdentifier(PersistentEntity param1, String param2, boolean param3) throws ResourceFactory.InvalidResourceException {
      // $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 0f
      // 04: iload 3
      // 05: ifeq 34
      // 08: goto 0f
      // 0b: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0e: athrow
      // 0f: aload 1
      // 10: aload 0
      // 11: aload 2
      // 12: invokevirtual com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.toInternalId (Ljava/lang/String;)Lcom/l7tech/objectmodel/Goid;
      // 15: invokeinterface com/l7tech/objectmodel/PersistentEntity.setGoid (Lcom/l7tech/objectmodel/Goid;)V 2
      // 1a: goto 34
      // 1d: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 20: athrow
      // 21: astore 4
      // 23: new com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
      // 26: dup
      // 27: getstatic com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType.INVALID_VALUES Lcom/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType;
      // 2a: getstatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.y [Ljava/lang/String;
      // 2d: bipush 24
      // 2f: aaload
      // 30: invokespecial com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException.<init> (Lcom/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType;Ljava/lang/String;)V
      // 33: athrow
      // 34: return
      // try (0 -> 4): 5 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceSelectors
      // try (7 -> 12): 15 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceSelectors
      // try (2 -> 13): 13 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
   }

   protected final void verifyIdentifier(Goid param1, Goid param2) throws ResourceFactory.InvalidResourceException {
      // $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: getstatic com/l7tech/objectmodel/PersistentEntity.DEFAULT_GOID Lcom/l7tech/objectmodel/Goid;
      // 03: aload 1
      // 04: invokevirtual com/l7tech/objectmodel/Goid.equals (Ljava/lang/Object;)Z
      // 07: ifne 3f
      // 0a: getstatic com/l7tech/objectmodel/PersistentEntity.DEFAULT_GOID Lcom/l7tech/objectmodel/Goid;
      // 0d: aload 2
      // 0e: invokevirtual com/l7tech/objectmodel/Goid.equals (Ljava/lang/Object;)Z
      // 11: ifne 3f
      // 14: goto 1b
      // 17: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1a: athrow
      // 1b: aload 1
      // 1c: aload 2
      // 1d: invokevirtual com/l7tech/objectmodel/Goid.equals (Ljava/lang/Object;)Z
      // 20: ifne 3f
      // 23: goto 2a
      // 26: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 29: athrow
      // 2a: new com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
      // 2d: dup
      // 2e: getstatic com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType.INVALID_VALUES Lcom/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType;
      // 31: getstatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.y [Ljava/lang/String;
      // 34: bipush 8
      // 36: aaload
      // 37: invokespecial com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException.<init> (Lcom/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType;Ljava/lang/String;)V
      // 3a: athrow
      // 3b: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 3e: athrow
      // 3f: return
      // try (0 -> 8): 9 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
      // try (4 -> 15): 16 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
      // try (11 -> 26): 26 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
   }

   protected final void setVersion(PersistentEntity var1, Integer var2) {
      var1.setVersion((Integer)Option.optional(var2).orSome(Integer.MIN_VALUE));
   }

   protected final void verifyVersion(int param1, int param2) throws ResourceFactory.InvalidResourceException {
      // $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: iload 2
      // 01: ldc -2147483648
      // 03: if_icmpeq 26
      // 06: iload 1
      // 07: iload 2
      // 08: if_icmpeq 26
      // 0b: goto 12
      // 0e: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 11: athrow
      // 12: new com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
      // 15: dup
      // 16: getstatic com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType.INVALID_VALUES Lcom/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType;
      // 19: getstatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.y [Ljava/lang/String;
      // 1c: bipush 4
      // 1d: aaload
      // 1e: invokespecial com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException.<init> (Lcom/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException$ExceptionType;Ljava/lang/String;)V
      // 21: athrow
      // 22: invokestatic com/l7tech/external/assertions/gatewaymanagement/server/EntityManagerResourceFactory.d (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 25: athrow
      // 26: return
      // try (0 -> 6): 7 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
      // try (3 -> 17): 17 com/l7tech/external/assertions/gatewaymanagement/server/ResourceFactory$InvalidResourceException
   }

   protected final <T> T cast(Object var1, Class<T> var2) {
      try {
         if (!var2.isInstance(var1)) {
            throw new ResourceFactory.ResourceAccessException(y[14]);
         } else {
            return (T)var1;
         }
      } catch (PermissionDeniedException var3) {
         throw d(var3);
      }
   }

   EntityManagerResourceFactory(boolean var1, boolean var2, RbacServices var3, SecurityFilter var4, PlatformTransactionManager var5, EntityManager<E, EH> var6) {
      this(var1, var2, false, var3, var4, var5, var6);
   }

   EntityManagerResourceFactory(
      boolean var1, boolean var2, boolean var3, RbacServices var4, SecurityFilter var5, PlatformTransactionManager var6, EntityManager<E, EH> var7
   ) {
      super(var4, var5, var6);
      this.k = var1;
      this.l = var2;
      this.m = var3;
      this.n = var7;
   }

   final <R> R a(UnaryThrows<R, EntityManager<E, EH>, ObjectModelException> var1) throws ObjectModelException {
      return (R)var1.call(this.n);
   }

   private void a() {
      try {
         if (this.isReadOnly()) {
            throw new IllegalStateException(y[20]);
         }
      } catch (PermissionDeniedException var1) {
         throw d(var1);
      }
   }

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

   static {
      String[] var5 = new String[28];
      int var3 = 0;
      String var2 = "pk,RtPKG.1Ru\u0002NM{1Y!\u0007Tk-NhMF\u000fla+\u001dhOXNk2XoVMF\bQk3XbVGP\u000fK`)\\mKL\u0002x:OrKGL\u0004Lo2X\u0004E{6Y\fQk3XbVmLz6Ix\u0013Kj:SuKNKk-\u001dlK[Oo+^iTAa2\u0012m\u0015\\Gm7\u0012dZ\\G|1\\m\rIQ}:OuKGL}pZ`VMUo&P`LIEk2XoV\u0007Qk-KdP\u0007g`+Tu[eC`>ZdPzG}0HsAMdo<InPQ*b@0IOWDN.2XuJGF.zN/\u0007[\u0002c*Nu\u0002FMz\u007fOdV]P`\u007fStND\u0013Ek+odS]K|:YRGDGm+Rs\bog,NhLO\u0002\bk`)\\mKL\u0002\fk`)\\mKL\u0002z&Md\u000bQk3XbVGPC>M\u0014W~;\\uG\bLa+\u001drWXRa-IdF\u0002Kj\u0004Lo2X\u0013Ek+odS]K|:YRGDGm+Rs\tpk>Y!MFNw\u0007Tk-NhMF\u0002Kj\u0014W~;\\uG\bLa+\u001drWXRa-IdF\u0012K`)\\mKL\u0002g;XoVADg:O>c|8HlGFV.9Rs\u0002hla+stND\u0002~>O`OMVk-\u001d&\u0007[\u0005.0[!\u0007[\f+,\u001dlW[V.1Ru\u0002JG.1HmN";
      int var4 = "pk,RtPKG.1Ru\u0002NM{1Y!\u0007Tk-NhMF\u000fla+\u001dhOXNk2XoVMF\bQk3XbVGP\u000fK`)\\mKL\u0002x:OrKGL\u0004Lo2X\u0004E{6Y\fQk3XbVmLz6Ix\u0013Kj:SuKNKk-\u001dlK[Oo+^iTAa2\u0012m\u0015\\Gm7\u0012dZ\\G|1\\m\rIQ}:OuKGL}pZ`VMUo&P`LIEk2XoV\u0007Qk-KdP\u0007g`+Tu[eC`>ZdPzG}0HsAMdo<InPQ*b@0IOWDN.2XuJGF.zN/\u0007[\u0002c*Nu\u0002FMz\u007fOdV]P`\u007fStND\u0013Ek+odS]K|:YRGDGm+Rs\bog,NhLO\u0002\bk`)\\mKL\u0002\fk`)\\mKL\u0002z&Md\u000bQk3XbVGPC>M\u0014W~;\\uG\bLa+\u001drWXRa-IdF\u0002Kj\u0004Lo2X\u0013Ek+odS]K|:YRGDGm+Rs\tpk>Y!MFNw\u0007Tk-NhMF\u0002Kj\u0014W~;\\uG\bLa+\u001drWXRa-IdF\u0012K`)\\mKL\u0002g;XoVADg:O>c|8HlGFV.9Rs\u0002hla+stND\u0002~>O`OMVk-\u001d&\u0007[\u0005.0[!\u0007[\f+,\u001dlW[V.1Ru\u0002JG.1HmN"
         .length();
      char var1 = 19;
      int var7 = -1;

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

         while (true) {
            String var8 = b(var10000, e(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     y = var5;
                     String[] var9 = y;
                     i = y[18];
                     g = var9[22];
                     h = var9[6];
                     j = var9[21];
                     return;
                  }

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

                  var2 = "\u001b%h\u0007T\u001f?lL3K\u0002\u00193iL:\u0004\u0002\u0019\"o\u00023S\u0017\u000f#d\u0011+\u0015\u0019\u0012#.\u0004>\b\u0013\u000b1x\u000e>\u0012\u0017\u001b5l\u00061\bY\u000f5s\u0015:\u000eY9>u\n+\u0005;\u001d>`\u0004:\u000e$\u0019#n\u0016-\u001f\u0013:1b\u00170\u000e\u000f";
                  var4 = "\u001b%h\u0007T\u001f?lL3K\u0002\u00193iL:\u0004\u0002\u0019\"o\u00023S\u0017\u000f#d\u0011+\u0015\u0019\u0012#.\u0004>\b\u0013\u000b1x\u000e>\u0012\u0017\u001b5l\u00061\bY\u000f5s\u0015:\u000eY9>u\n+\u0005;\u001d>`\u0004:\u000e$\u0019#n\u0016-\u001f\u0013:1b\u00170\u000e\u000f"
                     .length();
                  var1 = 4;
                  var7 = -1;
            }

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

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

      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 -> 117;
            case 1 -> 89;
            case 2 -> 8;
            case 3 -> 106;
            case 4 -> 86;
            case 5 -> 117;
            default -> 127;
         });
      }

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

   public static class EntityBag<BE extends PersistentEntity> implements Iterable<PersistentEntity> {
      private final BE a;

      protected EntityBag(BE var1) {
         this.a = (BE)var1;
      }

      public BE getEntity() {
         return this.a;
      }

      @Override
      public Iterator<PersistentEntity> iterator() {
         return Collections.singletonList(this.a).iterator();
      }
   }
}
