package com.l7tech.gateway.common.uddi;

import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.imp.ZoneableEntityImp;
import com.l7tech.security.rbac.RbacAttribute;
import com.l7tech.uddi.UDDIKeyedReference;
import com.l7tech.uddi.UDDIUtilities;
import com.l7tech.util.DeserializeSafe;
import com.l7tech.util.HexUtils;
import com.l7tech.util.SafeXMLDecoder;
import com.l7tech.util.SafeXMLDecoderBuilder;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.Lob;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;

@Entity
@Proxy(lazy = false)
@Table(name = "uddi_proxied_service_info")
@DeserializeSafe
public class UDDIProxiedServiceInfo extends ZoneableEntityImp {
   public static final String ATTR_SERVICE_GOID;
   public static final String ALL_ENDPOINT_PAIRS_KEY;
   public static final String ALL_BINDING_TEMPLATE_KEYS;
   public static final String FUNCTIONAL_ENDPOINT_KEY;
   public static final String GIF_SCHEME;
   public static final String IS_GIF;
   public static final String KEYED_REFERENCES_CONFIG;
   public static final String KEYED_REFERENCES_RUNTIME;
   private static final Logger logger;
   private Goid publishedServiceGoid;
   private Goid uddiRegistryGoid;
   private String uddiBusinessKey;
   private String uddiBusinessName;
   private boolean updateProxyOnLocalChange;
   private boolean createdFromExistingService;
   private boolean metricsEnabled;
   private Set<UDDIProxiedService> proxiedServices = new HashSet<>();
   private UDDIProxiedServiceInfo.PublishType publishType;
   private boolean publishWsPolicyEnabled;
   private boolean publishWsPolicyFull;
   private boolean publishWsPolicyInlined;
   private String wsdlHash;
   private boolean removeOtherBindings;
   private String propsXml;
   private Map<String, Object> props = new HashMap<>();
   static final long serialVersionUID = -7989710203045960788L;
   private static final String[] b;

   private static UDDIProxiedServiceInfo getUDDIProxiedServiceInfo(
      Goid var0, Goid var1, String var2, String var3, String var4, UDDIProxiedServiceInfo.PublishType var5
   ) {
      UDDIProxiedServiceInfo var6 = new UDDIProxiedServiceInfo();
      var6.setPublishedServiceGoid(var0);
      var6.setUddiRegistryGoid(var1);
      var6.setUddiBusinessKey(var2);
      var6.setUddiBusinessName(var3);
      var6.setWsdlHash(var4);
      var6.setPublishType(var5);
      return var6;
   }

   public static UDDIProxiedServiceInfo getGifEndPointPublishInfo(Goid var0, Goid var1, String var2, String var3, String var4) {
      UDDIProxiedServiceInfo var5 = getUDDIProxiedServiceInfo(var0, var1, var2, var3, var4, UDDIProxiedServiceInfo.PublishType.ENDPOINT);
      var5.setProperty(b[2], Boolean.TRUE);
      return var5;
   }

   public static UDDIProxiedServiceInfo getEndPointPublishInfo(Goid var0, Goid var1, String var2, String var3, String var4, boolean var5) {
      UDDIProxiedServiceInfo var6 = getUDDIProxiedServiceInfo(var0, var1, var2, var3, var4, UDDIProxiedServiceInfo.PublishType.ENDPOINT);
      var6.setRemoveOtherBindings(var5);
      return var6;
   }

   public static UDDIProxiedServiceInfo getProxyServicePublishInfo(Goid var0, Goid var1, String var2, String var3, String var4, boolean var5) {
      UDDIProxiedServiceInfo var6 = getUDDIProxiedServiceInfo(var0, var1, var2, var3, var4, UDDIProxiedServiceInfo.PublishType.PROXY);
      var6.setUpdateProxyOnLocalChange(var5);
      return var6;
   }

   public static UDDIProxiedServiceInfo getOverwriteProxyServicePublishInfo(Goid var0, Goid var1, String var2, String var3, String var4, boolean var5) {
      UDDIProxiedServiceInfo var6 = getUDDIProxiedServiceInfo(var0, var1, var2, var3, var4, UDDIProxiedServiceInfo.PublishType.OVERWRITE);
      var6.setUpdateProxyOnLocalChange(var5);
      return var6;
   }

   public void copyConfigModifiableProperties(UDDIProxiedServiceInfo var1) {
      this.setUpdateProxyOnLocalChange(var1.isUpdateProxyOnLocalChange());
      this.setMetricsEnabled(var1.isMetricsEnabled());
      this.setPublishWsPolicyEnabled(var1.isPublishWsPolicyEnabled());
      this.setPublishWsPolicyFull(var1.isPublishWsPolicyFull());
      this.setPublishWsPolicyInlined(var1.isPublishWsPolicyInlined());
      this.setSecurityZone(var1.getSecurityZone());
      String[] var3 = b;
      Set var2 = var1.getProperty(var3[1]);
      this.setProperty(var3[7], var2);
   }

   public boolean areKeyedReferencesDifferent(Set<UDDIKeyedReference> var1) {
      Set var2 = this.getProperty(b[7]);
      boolean var3;
      if (var1 != null && var2 != null) {
         var3 = !var2.containsAll(var1) || var2.size() != var1.size();
         if (!var3) {
            HashMap var8 = new HashMap();

            for (UDDIKeyedReference var6 : var2) {
               var8.put(var6, var6);
            }

            for (UDDIKeyedReference var11 : var1) {
               if (var8.containsKey(var11)) {
                  UDDIKeyedReference var7 = (UDDIKeyedReference)var8.get(var11);
                  var3 = UDDIUtilities.areNamesDifferent(var7.getKeyName(), var11.getKeyName());
               }
            }
         }
      } else {
         boolean var4 = var1 == null;
         boolean var5 = var2 == null;
         var3 = var4 != var5;
      }

      return var3;
   }

   @Version
   @Column(name = "version")
   public int getVersion() {
      return super.getVersion();
   }

   @Column(name = "published_service_goid", updatable = false)
   @Type(type = "com.l7tech.server.util.GoidType")
   public Goid getPublishedServiceGoid() {
      return this.publishedServiceGoid;
   }

   public void setPublishedServiceGoid(Goid var1) {
      this.publishedServiceGoid = var1;
   }

   @Column(name = "uddi_registry_goid", updatable = false)
   @Type(type = "com.l7tech.server.util.GoidType")
   public Goid getUddiRegistryGoid() {
      return this.uddiRegistryGoid;
   }

   public void setUddiRegistryGoid(Goid var1) {
      this.uddiRegistryGoid = var1;
   }

   @RbacAttribute
   @Column(name = "uddi_business_key", updatable = false)
   public String getUddiBusinessKey() {
      return this.uddiBusinessKey;
   }

   public void setUddiBusinessKey(String var1) {
      this.uddiBusinessKey = var1;
   }

   @RbacAttribute
   @Column(name = "uddi_business_name", updatable = false)
   public String getUddiBusinessName() {
      return this.uddiBusinessName;
   }

   public void setUddiBusinessName(String var1) {
      this.uddiBusinessName = var1;
   }

   @Column(name = "update_proxy_on_local_change")
   public boolean isUpdateProxyOnLocalChange() {
      return this.updateProxyOnLocalChange;
   }

   public void setUpdateProxyOnLocalChange(boolean var1) {
      this.updateProxyOnLocalChange = var1;
   }

   @Column(name = "created_from_existing", updatable = false)
   public boolean isCreatedFromExistingService() {
      return this.createdFromExistingService;
   }

   public void setCreatedFromExistingService(boolean var1) {
      this.createdFromExistingService = var1;
   }

   @Column(name = "metrics_enabled")
   public boolean isMetricsEnabled() {
      return this.metricsEnabled;
   }

   public void setMetricsEnabled(boolean var1) {
      this.metricsEnabled = var1;
   }

   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "uddiProxiedServiceInfo", orphanRemoval = true)
   @Fetch(FetchMode.SUBSELECT)
   @Cascade(org.hibernate.annotations.CascadeType.ALL)
   @OnDelete(action = OnDeleteAction.CASCADE)
   public Set<UDDIProxiedService> getProxiedServices() {
      return this.proxiedServices;
   }

   public void setProxiedServices(Set<UDDIProxiedService> var1) {
      this.proxiedServices = var1;
   }

   @RbacAttribute
   @Column(name = "publish_type")
   @Enumerated(EnumType.STRING)
   public UDDIProxiedServiceInfo.PublishType getPublishType() {
      return this.publishType;
   }

   public void setPublishType(UDDIProxiedServiceInfo.PublishType var1) {
      this.publishType = var1;
   }

   @Column(name = "publish_wspolicy_enabled")
   public boolean isPublishWsPolicyEnabled() {
      return this.publishWsPolicyEnabled;
   }

   public void setPublishWsPolicyEnabled(boolean var1) {
      this.publishWsPolicyEnabled = var1;
   }

   @Column(name = "publish_wspolicy_full")
   public boolean isPublishWsPolicyFull() {
      return this.publishWsPolicyFull;
   }

   public void setPublishWsPolicyFull(boolean var1) {
      this.publishWsPolicyFull = var1;
   }

   @Column(name = "publish_wspolicy_inlined")
   public boolean isPublishWsPolicyInlined() {
      return this.publishWsPolicyInlined;
   }

   public void setPublishWsPolicyInlined(boolean var1) {
      this.publishWsPolicyInlined = var1;
   }

   @Column(name = "wsdl_hash")
   public String getWsdlHash() {
      return this.wsdlHash;
   }

   public void setWsdlHash(String var1) {
      this.wsdlHash = var1;
   }

   @Column(name = "remove_other_bindings", updatable = false)
   public boolean isRemoveOtherBindings() {
      return this.removeOtherBindings;
   }

   public void setRemoveOtherBindings(boolean var1) {
      this.removeOtherBindings = var1;
   }

   @Column(name = "properties", length = Integer.MAX_VALUE)
   @Lob
   public String getSerializedProps() throws IOException {
      // $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: getfield com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.propsXml Ljava/lang/String;
      // 04: ifnonnull 90
      // 07: aload 0
      // 08: getfield com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.props Ljava/util/Map;
      // 0b: invokeinterface java/util/Map.size ()I 1
      // 10: bipush 1
      // 11: if_icmpge 28
      // 14: goto 1b
      // 17: invokestatic com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 1a: athrow
      // 1b: aload 0
      // 1c: ldc ""
      // 1e: putfield com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.propsXml Ljava/lang/String;
      // 21: goto 90
      // 24: invokestatic com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 27: athrow
      // 28: aconst_null
      // 29: astore 1
      // 2a: aconst_null
      // 2b: astore 2
      // 2c: new com/l7tech/util/PoolByteArrayOutputStream
      // 2f: dup
      // 30: invokespecial com/l7tech/util/PoolByteArrayOutputStream.<init> ()V
      // 33: astore 1
      // 34: new java/beans/XMLEncoder
      // 37: dup
      // 38: new com/l7tech/common/io/NonCloseableOutputStream
      // 3b: dup
      // 3c: aload 1
      // 3d: invokespecial com/l7tech/common/io/NonCloseableOutputStream.<init> (Ljava/io/OutputStream;)V
      // 40: invokespecial java/beans/XMLEncoder.<init> (Ljava/io/OutputStream;)V
      // 43: astore 2
      // 44: aload 2
      // 45: new com/l7tech/gateway/common/uddi/a
      // 48: dup
      // 49: aload 0
      // 4a: invokespecial com/l7tech/gateway/common/uddi/a.<init> (Lcom/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo;)V
      // 4d: invokevirtual java/beans/XMLEncoder.setExceptionListener (Ljava/beans/ExceptionListener;)V
      // 50: aload 2
      // 51: aload 0
      // 52: getfield com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.props Ljava/util/Map;
      // 55: invokevirtual java/beans/XMLEncoder.writeObject (Ljava/lang/Object;)V
      // 58: aload 2
      // 59: invokevirtual java/beans/XMLEncoder.close ()V
      // 5c: aconst_null
      // 5d: astore 2
      // 5e: aload 0
      // 5f: aload 1
      // 60: getstatic com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.b [Ljava/lang/String;
      // 63: bipush 4
      // 64: aaload
      // 65: invokevirtual com/l7tech/util/PoolByteArrayOutputStream.toString (Ljava/lang/String;)Ljava/lang/String;
      // 68: putfield com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.propsXml Ljava/lang/String;
      // 6b: aload 2
      // 6c: ifnull 73
      // 6f: aload 2
      // 70: invokevirtual java/beans/XMLEncoder.close ()V
      // 73: aload 1
      // 74: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // 77: goto 90
      // 7a: astore 3
      // 7b: aload 2
      // 7c: ifnull 8a
      // 7f: aload 2
      // 80: invokevirtual java/beans/XMLEncoder.close ()V
      // 83: goto 8a
      // 86: invokestatic com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 89: athrow
      // 8a: aload 1
      // 8b: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // 8e: aload 3
      // 8f: athrow
      // 90: aload 0
      // 91: getfield com/l7tech/gateway/common/uddi/UDDIProxiedServiceInfo.propsXml Ljava/lang/String;
      // 94: areturn
      // try (3 -> 15): 15 java/io/IOException
      // try (0 -> 8): 9 java/io/IOException
      // try (21 -> 54): 61 null
      // try (62 -> 66): 67 java/io/IOException
   }

   public void setSerializedProps(String var1) {
      this.propsXml = var1;
      if (var1 != null && var1.length() >= 2) {
         ByteArrayInputStream var2 = new ByteArrayInputStream(HexUtils.encodeUtf8(var1));
         SafeXMLDecoder var3 = new SafeXMLDecoderBuilder(var2).setExceptionListener(new b(this)).build();
         this.props = (Map<String, Object>)var3.readObject();
      } else {
         this.props.clear();
      }
   }

   public <T> T getProperty(String var1) {
      return (T)this.props.get(var1);
   }

   public void setProperty(String var1, Object var2) {
      if (var2 == null) {
         this.props.remove(var1);
      } else {
         this.props.put(var1, var2);
      }

      this.propsXml = null;
   }

   static {
      String[] var5 = new String[11];
      int var3 = 0;
      String var2 = "\u001d\u000b\u0000$\u000eZx\u001f\u000f\u0003\u0017\u0011\u0007\u001f>\u0019Fb\u001f\u0004\u0003)\u0018Ws\u001f\u0011\u00198\u0012Wv\u0013\u0005\u0006\u0013\u0011\u0019<\u0014_\u0017\u001c\u0017\b8\tP\u007f\u0014\u0003\n$\u0018Wt\n\r\u000f5\tF{\u001f\u001b\u0005\u000f\u0016\u0000Ve\u0018\u0011\u0007\u001f>\u0019Fb\u001f\u0004\u0003)\u0018Ws\u001f\u0011\u0019)\bWd\u0013\u000f\u0003\u0016\u001b\u000e\n$\u0018Wt\n\r\u000f5\tF`\u001b\u000b\u0014(\u0002Ru\u0003\u0017\u0011\u0007\u001f>\u0019Fb\u001f\u0004\u0003)\u0018Ws\u001f\u0011\u00198\u0012Wv\u0013\u0005\u0014*7$\u00174jX?&\u0015\u001e/oY9'\u0001\u00144}";
      int var4 = "\u001d\u000b\u0000$\u000eZx\u001f\u000f\u0003\u0017\u0011\u0007\u001f>\u0019Fb\u001f\u0004\u0003)\u0018Ws\u001f\u0011\u00198\u0012Wv\u0013\u0005\u0006\u0013\u0011\u0019<\u0014_\u0017\u001c\u0017\b8\tP\u007f\u0014\u0003\n$\u0018Wt\n\r\u000f5\tF{\u001f\u001b\u0005\u000f\u0016\u0000Ve\u0018\u0011\u0007\u001f>\u0019Fb\u001f\u0004\u0003)\u0018Ws\u001f\u0011\u0019)\bWd\u0013\u000f\u0003\u0016\u001b\u000e\n$\u0018Wt\n\r\u000f5\tF`\u001b\u000b\u0014(\u0002Ru\u0003\u0017\u0011\u0007\u001f>\u0019Fb\u001f\u0004\u0003)\u0018Ws\u001f\u0011\u00198\u0012Wv\u0013\u0005\u0014*7$\u00174jX?&\u0015\u001e/oY9'\u0001\u00144}"
         .length();
      char var1 = '\n';
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 4;
         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;
                     String[] var9 = b;
                     KEYED_REFERENCES_CONFIG = b[7];
                     ALL_BINDING_TEMPLATE_KEYS = var9[9];
                     IS_GIF = var9[10];
                     KEYED_REFERENCES_RUNTIME = var9[5];
                     FUNCTIONAL_ENDPOINT_KEY = var9[3];
                     ATTR_SERVICE_GOID = var9[8];
                     ALL_ENDPOINT_PAIRS_KEY = var9[6];
                     GIF_SCHEME = var9[0];
                     logger = Logger.getLogger(UDDIProxiedServiceInfo.class.getName());
                     return;
                  }

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

                  var2 = "*?;\u0015.aO/:9\r3|D&#;\u000b8m^ 6.\u0019\u0006\" (\r%n";
                  var4 = "*?;\u0015.aO/:9\r3|D&#;\u000b8m^ 6.\u0019\u0006\" (\r%n".length();
                  var1 = 25;
                  var7 = -1;
            }

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

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

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

      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 -> 94;
            case 1 -> 70;
            case 2 -> 66;
            case 3 -> 127;
            case 4 -> 89;
            case 5 -> 29;
            default -> 52;
         });
      }

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

   public enum PublishType {
      PROXY,
      ENDPOINT,
      OVERWRITE;

      // $VF: Failed to inline enum fields
      // 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!)
      static {
         String[] var0 = new String[3];
         int var4 = 0;
         String var3 = "XZAB\u000f\tG^KH\u0001\u0012a\\M\bMFJJ\u0019\tf\\";
         int var5 = "XZAB\u000f\tG^KH\u0001\u0012a\\M\bMFJJ\u0019\tf\\".length();
         char var2 = 5;
         int var1 = -1;

         while (true) {
            String var10002 = a(49, a(var3.substring(++var1, var1 + var2)));
            byte var10001 = -1;
            var0[var4++] = var10002;
            if ((var1 += var2) >= var5) {
               PROXY = new UDDIProxiedServiceInfo.PublishType();
               ENDPOINT = new UDDIProxiedServiceInfo.PublishType();
               OVERWRITE = new UDDIProxiedServiceInfo.PublishType();
               return;
            }

            var2 = var3.charAt(var1);
         }
      }

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

         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 -> 57;
               case 1 -> 57;
               case 2 -> 63;
               case 3 -> 43;
               case 4 -> 103;
               case 5 -> 113;
               default -> 25;
            });
         }

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