package com.l7tech.gateway.common.transport.firewall;

import com.l7tech.objectmodel.imp.NamedEntityImp;
import com.l7tech.security.rbac.RbacAttribute;
import com.l7tech.util.BeanUtils;
import com.l7tech.util.DeserializeSafe;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.MapKeyColumn;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "firewall_rule")
@DeserializeSafe
public class SsgFirewallRule extends NamedEntityImp {
   protected static final Logger logger;
   private int ordinal;
   private boolean enabled = true;
   private Map<String, String> properties = new HashMap<>();
   static final long serialVersionUID = -1224654639532024940L;
   private static final String[] b;

   public SsgFirewallRule() {
   }

   public SsgFirewallRule(boolean var1, int var2, String var3) {
      this.enabled = var1;
      this.ordinal = var2;
      this.setName(var3);
   }

   @Column(name = "ordinal")
   public int getOrdinal() {
      return this.ordinal;
   }

   public void setOrdinal(int var1) {
      this.checkLocked();
      this.ordinal = var1;
   }

   @RbacAttribute
   @Column(name = "enabled")
   public boolean isEnabled() {
      return this.enabled;
   }

   public void setEnabled(boolean var1) {
      this.checkLocked();
      this.enabled = var1;
   }

   @Fetch(FetchMode.SUBSELECT)
   @ElementCollection(fetch = FetchType.EAGER)
   @JoinTable(name = "firewall_rule_property", joinColumns = @JoinColumn(name = "firewall_rule_goid", referencedColumnName = "goid"))
   @MapKeyColumn(name = "name", length = 128)
   @Column(name = "value", nullable = false, length = 32672)
   protected Map<String, String> getProperties() {
      return this.properties;
   }

   protected void setProperties(Map<String, String> var1) {
      this.checkLocked();
      this.properties = var1;
   }

   @Transient
   public List<String> getPropertyNames() {
      return new ArrayList<>(this.properties.keySet());
   }

   public String getProperty(String var1) {
      return this.properties.get(var1);
   }

   public void putProperty(String var1, String var2) {
      this.checkLocked();
      this.properties.put(var1, var2);
   }

   public String removeProperty(String var1) {
      this.checkLocked();
      return this.properties.remove(var1);
   }

   @Transient
   public String getProtocol() {
      return this.properties.get(b[1]);
   }

   @Transient
   public String getPort() {
      return this.properties.get(b[2]);
   }

   @Transient
   public String getJump() {
      return this.properties.get(b[4]);
   }

   @Transient
   public String getInInterface() {
      String[] var2 = b;
      String var1 = this.properties.get(var2[0]);

      try {
         if (var1 == null) {
            return var2[5];
         }
      } catch (RuntimeException var3) {
         throw a(var3);
      }

      return var1;
   }

   @Transient
   public SsgFirewallRule getCopy() {
      try {
         SsgFirewallRule var1 = new SsgFirewallRule();
         BeanUtils.copyProperties(this, var1, BeanUtils.omitProperties(BeanUtils.getProperties(this.getClass()), new String[]{b[3]}));
         var1.setProperties(new HashMap<>(this.getProperties()));
         return var1;
      } catch (InvocationTargetException var2) {
         throw new RuntimeException(var2);
      } catch (IllegalAccessException var3) {
         throw new RuntimeException(var3);
      }
   }

   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/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 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/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 20: athrow
      // 21: bipush 0
      // 22: ireturn
      // 23: invokestatic com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 26: athrow
      // 27: aload 0
      // 28: aload 1
      // 29: invokespecial com/l7tech/objectmodel/imp/NamedEntityImp.equals (Ljava/lang/Object;)Z
      // 2c: ifne 35
      // 2f: bipush 0
      // 30: ireturn
      // 31: invokestatic com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 34: athrow
      // 35: aload 1
      // 36: checkcast com/l7tech/gateway/common/transport/firewall/SsgFirewallRule
      // 39: astore 2
      // 3a: aload 0
      // 3b: getfield com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.enabled Z
      // 3e: aload 2
      // 3f: getfield com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.enabled Z
      // 42: if_icmpeq 4b
      // 45: bipush 0
      // 46: ireturn
      // 47: invokestatic com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 4a: athrow
      // 4b: aload 0
      // 4c: getfield com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.properties Ljava/util/Map;
      // 4f: ifnull 70
      // 52: aload 0
      // 53: getfield com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.properties Ljava/util/Map;
      // 56: aload 2
      // 57: getfield com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.properties Ljava/util/Map;
      // 5a: invokeinterface java/util/Map.equals (Ljava/lang/Object;)Z 2
      // 5f: ifne 7d
      // 62: goto 69
      // 65: invokestatic com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 68: athrow
      // 69: goto 77
      // 6c: invokestatic com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 6f: athrow
      // 70: aload 2
      // 71: getfield com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.properties Ljava/util/Map;
      // 74: ifnull 7d
      // 77: bipush 0
      // 78: ireturn
      // 79: invokestatic com/l7tech/gateway/common/transport/firewall/SsgFirewallRule.a (Ljava/lang/RuntimeException;)Ljava/lang/RuntimeException;
      // 7c: athrow
      // 7d: bipush 1
      // 7e: ireturn
      // try (0 -> 5): 5 java/lang/RuntimeException
      // try (7 -> 14): 15 java/lang/RuntimeException
      // try (9 -> 19): 19 java/lang/RuntimeException
      // try (21 -> 27): 27 java/lang/RuntimeException
      // try (32 -> 39): 39 java/lang/RuntimeException
      // try (41 -> 50): 51 java/lang/RuntimeException
      // try (44 -> 54): 54 java/lang/RuntimeException
      // try (56 -> 61): 61 java/lang/RuntimeException
   }

   public int hashCode() {
      int var1 = super.hashCode();

      int var10000;
      byte var10001;
      label31: {
         try {
            var10000 = 31 * var1;
            if (this.enabled) {
               var10001 = 1;
               break label31;
            }
         } catch (RuntimeException var3) {
            throw a(var3);
         }

         var10001 = 0;
      }

      var1 = var10000 + var10001;

      try {
         var10000 = 31 * var1;
         if (this.properties != null) {
            return var10000 + this.properties.hashCode();
         }
      } catch (RuntimeException var2) {
         throw a(var2);
      }

      return var10000 + 0;
   }

   static {
      String[] var5 = new String[6];
      int var3 = 0;
      String var2 = "\\UsHz<iG]?Bq\bEI1U{+cY\u0010Q^-U}&mAR1O98cGO\nEI1Qq:x\\^-";
      int var4 = "\\UsHz<iG]?Bq\bEI1U{+cY\u0010Q^-U}&mAR1O98cGO\nEI1Qq:x\\^-".length();
      char var1 = '\f';
      int var7 = -1;

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

         while (true) {
            String var8 = b(var10000, b(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     b = var5;
                     logger = Logger.getLogger(SsgFirewallRule.class.getName());
                     return;
                  }

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

                  var2 = "!0M/\u0005c\u0004l\u0013C";
                  var4 = "!0M/\u0005c\u0004l\u0013C".length();
                  var1 = 4;
                  var7 = -1;
            }

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

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

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

      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 -> 84;
            case 1 -> 90;
            case 2 -> 63;
            case 3 -> 64;
            case 4 -> 117;
            case 5 -> 41;
            default -> 109;
         });
      }

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