package com.l7tech.objectmodel.imp;

import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.PersistentEntity;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Transient;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlID;
import jakarta.xml.bind.annotation.XmlTransient;
import java.io.Serializable;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

@MappedSuperclass
public abstract class PersistentEntityImp implements PersistentEntity, Serializable {
   private Goid goid = DEFAULT_GOID;
   private int version;
   protected final transient long loadTime = System.currentTimeMillis();
   protected transient boolean locked = false;
   protected transient boolean preserveId = false;
   private static final long serialVersionUID = 5416621649996405984L;
   private static final String a;

   protected PersistentEntityImp() {
   }

   protected PersistentEntityImp(PersistentEntity var1) {
      this();
      this.setGoid(var1.getGoid());
      this.setVersion(var1.getVersion());
   }

   @Id
   @XmlTransient
   @Column(name = "goid", nullable = false, updatable = false)
   @GenericGenerator(name = "layer7-goid-generator", strategy = "com.l7tech.server.util.ConfiguredSessionFactoryBean$ConfiguredGOIDGenerator")
   @GeneratedValue(generator = "layer7-goid-generator")
   @Type(type = "com.l7tech.server.util.GoidType")
   @Override
   public Goid getGoid() {
      return this.goid;
   }

   @Override
   public void setGoid(Goid var1) {
      this.goid = var1.clone();
   }

   @Transient
   @XmlTransient
   @Override
   public boolean isUnsaved() {
      return DEFAULT_GOID.equals(this.goid);
   }

   @Transient
   @XmlTransient
   boolean isPreserveId() {
      return this.preserveId;
   }

   void preserveId() {
      this.preserveId = true;
   }

   @Transient
   @XmlAttribute
   @Override
   public int getVersion() {
      return this.version;
   }

   @Override
   public void setVersion(int var1) {
      this.checkLocked();
      this.version = var1;
   }

   @Transient
   @XmlID
   @XmlAttribute
   @Override
   public String getId() {
      return this.goid.toString();
   }

   @Deprecated
   public void setId(String param1) {
      // $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 0
      // 01: invokevirtual com/l7tech/objectmodel/imp/PersistentEntityImp.checkLocked ()V
      // 04: aload 1
      // 05: ifnull 16
      // 08: aload 1
      // 09: invokevirtual java/lang/String.length ()I
      // 0c: ifne 24
      // 0f: goto 16
      // 12: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 15: athrow
      // 16: aload 0
      // 17: getstatic com/l7tech/objectmodel/imp/PersistentEntityImp.DEFAULT_GOID Lcom/l7tech/objectmodel/Goid;
      // 1a: invokevirtual com/l7tech/objectmodel/imp/PersistentEntityImp.setGoid (Lcom/l7tech/objectmodel/Goid;)V
      // 1d: goto 3e
      // 20: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 23: athrow
      // 24: aload 0
      // 25: aload 0
      // 26: invokevirtual java/lang/Object.getClass ()Ljava/lang/Class;
      // 29: invokestatic com/l7tech/objectmodel/EntityType.findTypeByEntity (Ljava/lang/Class;)Lcom/l7tech/objectmodel/EntityType;
      // 2c: aload 1
      // 2d: invokestatic com/l7tech/util/GoidUpgradeMapper.mapId (Lcom/l7tech/objectmodel/EntityType;Ljava/lang/String;)Lcom/l7tech/objectmodel/Goid;
      // 30: invokevirtual com/l7tech/objectmodel/imp/PersistentEntityImp.setGoid (Lcom/l7tech/objectmodel/Goid;)V
      // 33: goto 3e
      // 36: astore 2
      // 37: aload 0
      // 38: getstatic com/l7tech/objectmodel/imp/PersistentEntityImp.DEFAULT_GOID Lcom/l7tech/objectmodel/Goid;
      // 3b: invokevirtual com/l7tech/objectmodel/imp/PersistentEntityImp.setGoid (Lcom/l7tech/objectmodel/Goid;)V
      // 3e: return
      // try (4 -> 14): 14 java/lang/IllegalArgumentException
      // try (0 -> 7): 8 java/lang/IllegalArgumentException
      // try (16 -> 23): 24 java/lang/IllegalArgumentException
   }

   protected void lock() {
      this.locked = true;
   }

   @Transient
   protected boolean isLocked() {
      return this.locked;
   }

   protected void checkLocked() {
      try {
         if (this.isLocked()) {
            throw new IllegalStateException(a);
         }
      } catch (IllegalArgumentException var1) {
         throw a(var1);
      }
   }

   @Override
   public boolean equals(Object param1) {
      // $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 0
      // 01: aload 1
      // 02: if_acmpne 0b
      // 05: bipush 1
      // 06: ireturn
      // 07: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 0a: athrow
      // 0b: aload 1
      // 0c: ifnull 21
      // 0f: aload 0
      // 10: invokevirtual java/lang/Object.getClass ()Ljava/lang/Class;
      // 13: aload 1
      // 14: invokevirtual java/lang/Object.getClass ()Ljava/lang/Class;
      // 17: if_acmpeq 27
      // 1a: goto 21
      // 1d: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 20: athrow
      // 21: bipush 0
      // 22: ireturn
      // 23: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 26: athrow
      // 27: aload 1
      // 28: checkcast com/l7tech/objectmodel/imp/PersistentEntityImp
      // 2b: astore 2
      // 2c: aload 0
      // 2d: getfield com/l7tech/objectmodel/imp/PersistentEntityImp.goid Lcom/l7tech/objectmodel/Goid;
      // 30: ifnull 4f
      // 33: aload 0
      // 34: getfield com/l7tech/objectmodel/imp/PersistentEntityImp.goid Lcom/l7tech/objectmodel/Goid;
      // 37: aload 2
      // 38: getfield com/l7tech/objectmodel/imp/PersistentEntityImp.goid Lcom/l7tech/objectmodel/Goid;
      // 3b: invokevirtual com/l7tech/objectmodel/Goid.equals (Ljava/lang/Object;)Z
      // 3e: ifne 5c
      // 41: goto 48
      // 44: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 47: athrow
      // 48: goto 56
      // 4b: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 4e: athrow
      // 4f: aload 2
      // 50: getfield com/l7tech/objectmodel/imp/PersistentEntityImp.goid Lcom/l7tech/objectmodel/Goid;
      // 53: ifnull 5c
      // 56: bipush 0
      // 57: ireturn
      // 58: invokestatic com/l7tech/objectmodel/imp/PersistentEntityImp.a (Ljava/lang/IllegalArgumentException;)Ljava/lang/IllegalArgumentException;
      // 5b: athrow
      // 5c: bipush 1
      // 5d: ireturn
      // try (0 -> 5): 5 java/lang/IllegalArgumentException
      // try (7 -> 14): 15 java/lang/IllegalArgumentException
      // try (9 -> 19): 19 java/lang/IllegalArgumentException
      // try (24 -> 33): 34 java/lang/IllegalArgumentException
      // try (27 -> 37): 37 java/lang/IllegalArgumentException
      // try (39 -> 44): 44 java/lang/IllegalArgumentException
   }

   @Override
   public int hashCode() {
      try {
         if (this.goid != null) {
            return this.goid.hashCode();
         }
      } catch (IllegalArgumentException var1) {
         throw a(var1);
      }

      return 0;
   }

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

   static {
      String var10002 = a(34, a("7,*\\\u0003F2\u0001= S\u0018W2\u0018\"'Y\tV2\u0011#0[\u0018K"));
      byte var10001 = -1;
      a = var10002;
   }

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

      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 -> 86;
            case 1 -> 111;
            case 2 -> 102;
            case 3 -> 16;
            case 4 -> 78;
            case 5 -> 16;
            default -> 48;
         });
      }

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