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

import com.l7tech.gateway.common.security.password.SecurePasswordReferenceExpander;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.imp.ZoneableNamedEntityImp;
import com.l7tech.policy.wsp.WspSensitive;
import com.l7tech.search.Dependency;
import com.l7tech.search.Dependency.DependencyType;
import com.l7tech.search.Dependency.MethodReturnType;
import com.l7tech.security.rbac.RbacAttribute;
import com.l7tech.util.DeserializeSafe;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.net.PasswordAuthentication;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;

@XmlRootElement
@Entity
@Proxy(lazy = false)
@Table(name = "jms_endpoint")
@DeserializeSafe
public class JmsEndpoint extends ZoneableNamedEntityImp implements Serializable {
   public static final int DEFAULT_MAX_CONCURRENT_REQUESTS = 1;
   private Goid _connectionGoid;
   private boolean queue = true;
   private String _destinationName;
   private String _failureDestinationName;
   private JmsAcknowledgementType _acknowledgementType;
   private JmsReplyType _replyType = JmsReplyType.AUTOMATIC;
   private String _username;
   private String _password;
   private int _maxConcurrentRequests = 1;
   private boolean _messageSource;
   private String replyToQueueName;
   private JmsOutboundMessageType outboundMessageType = JmsOutboundMessageType.AUTOMATIC;
   private boolean disabled;
   private boolean useMessageIdForCorrelation;
   private boolean template;
   private long requestMaxSize = -1L;
   static final long serialVersionUID = 2606752206821587405L;
   private static final String[] b;

   public JmsEndpoint() {
   }

   public JmsEndpoint(JmsEndpoint var1, boolean var2) {
      this.copyFrom(var1);
      if (var2) {
         this.lock();
      }
   }

   public void copyFrom(JmsEndpoint var1) {
      this.setGoid(var1.getGoid());
      this.setVersion(var1.getVersion());
      this.setName(var1.getName());
      this.setQueue(var1.isQueue());
      this.setConnectionGoid(var1.getConnectionGoid());
      this.setDestinationName(var1.getDestinationName());
      this.setFailureDestinationName(var1.getFailureDestinationName());
      this.setAcknowledgementType(var1.getAcknowledgementType());
      this.setReplyType(var1.getReplyType());
      this.setUsername(var1.getUsername());
      this.setTemplate(var1.isTemplate());
      this.setPassword(var1.getPassword());
      this.setMaxConcurrentRequests(var1.getMaxConcurrentRequests());
      this.setMessageSource(var1.isMessageSource());
      this.setReplyToQueueName(var1.getReplyToQueueName());
      this.setOutboundMessageType(var1.getOutboundMessageType());
      this.setDisabled(var1.isDisabled());
      this.setUseMessageIdForCorrelation(var1.isUseMessageIdForCorrelation());
      this.setRequestMaxSize(var1.getRequestMaxSize());
      this.setSecurityZone(var1.getSecurityZone());
   }

   @Transient
   public PasswordAuthentication getPasswordAuthentication(SecurePasswordReferenceExpander param1) throws FindException {
      // $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/transport/jms/JmsEndpoint._username Ljava/lang/String;
      // 04: ifnull 31
      // 07: aload 0
      // 08: getfield com/l7tech/gateway/common/transport/jms/JmsEndpoint._password Ljava/lang/String;
      // 0b: ifnull 31
      // 0e: goto 15
      // 11: invokestatic com/l7tech/gateway/common/transport/jms/JmsEndpoint.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 14: athrow
      // 15: new java/net/PasswordAuthentication
      // 18: dup
      // 19: aload 0
      // 1a: getfield com/l7tech/gateway/common/transport/jms/JmsEndpoint._username Ljava/lang/String;
      // 1d: aload 1
      // 1e: aload 0
      // 1f: getfield com/l7tech/gateway/common/transport/jms/JmsEndpoint._password Ljava/lang/String;
      // 22: invokeinterface com/l7tech/gateway/common/security/password/SecurePasswordReferenceExpander.expandPasswordReference (Ljava/lang/String;)[C 2
      // 27: invokespecial java/net/PasswordAuthentication.<init> (Ljava/lang/String;[C)V
      // 2a: goto 32
      // 2d: invokestatic com/l7tech/gateway/common/transport/jms/JmsEndpoint.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 30: athrow
      // 31: aconst_null
      // 32: areturn
      // try (0 -> 6): 7 com/l7tech/objectmodel/FindException
      // try (3 -> 19): 19 com/l7tech/objectmodel/FindException
   }

   @RbacAttribute
   @Size(min = 1, max = 128)
   @Transient
   public String getName() {
      return super.getName();
   }

   @RbacAttribute
   @Size(max = 255)
   @Column(name = "username", length = 255)
   public String getUsername() {
      return this._username;
   }

   public void setUsername(String var1) {
      this.checkLocked();
      this._username = var1;
   }

   @Size(max = 255)
   @Column(name = "password", length = 255)
   @WspSensitive
   @Dependency(type = DependencyType.SECURE_PASSWORD, methodReturnType = MethodReturnType.VARIABLE)
   public String getPassword() {
      return this._password;
   }

   public void setPassword(String var1) {
      this.checkLocked();
      this._password = var1;
   }

   @Column(name = "max_concurrent_requests")
   public int getMaxConcurrentRequests() {
      return this._maxConcurrentRequests;
   }

   @RbacAttribute(displayNameIdentifier = "jms.messageSource")
   @Column(name = "is_message_source")
   public boolean isMessageSource() {
      return this._messageSource;
   }

   public void setMessageSource(boolean var1) {
      this.checkLocked();
      this._messageSource = var1;
   }

   public void setMaxConcurrentRequests(int var1) {
      this.checkLocked();
      this._maxConcurrentRequests = var1;
   }

   @Column(name = "connection_goid", nullable = false)
   @Type(type = "com.l7tech.server.util.GoidType")
   public Goid getConnectionGoid() {
      return this._connectionGoid;
   }

   public void setConnectionGoid(Goid var1) {
      this.checkLocked();
      this._connectionGoid = var1;
   }

   @RbacAttribute(displayNameIdentifier = "jms.queue")
   @Column(name = "destination_type")
   public boolean isQueue() {
      return this.queue;
   }

   public void setQueue(boolean var1) {
      this.checkLocked();
      this.queue = var1;
   }

   @RbacAttribute
   @Pattern(regexp = ".*?[^\\p{Space}].*")
   @NotNull(groups = JmsEndpoint.StandardValidationGroup.class)
   @Size(min = 1, max = 128)
   @Column(name = "destination_name", length = 128)
   public String getDestinationName() {
      return this._destinationName;
   }

   public void setDestinationName(String var1) {
      this.checkLocked();
      this._destinationName = var1;
   }

   @RbacAttribute
   @Pattern(regexp = ".*?[^\\p{Space}].*")
   @Size(max = 128)
   @Column(name = "failure_destination_name", length = 128)
   public String getFailureDestinationName() {
      return this._failureDestinationName;
   }

   public void setFailureDestinationName(String var1) {
      this.checkLocked();
      this._failureDestinationName = var1;
   }

   @Enumerated(EnumType.STRING)
   @Column(name = "acknowledgement_type")
   public JmsAcknowledgementType getAcknowledgementType() {
      return this._acknowledgementType;
   }

   public void setAcknowledgementType(JmsAcknowledgementType var1) {
      this.checkLocked();
      this._acknowledgementType = var1;
   }

   @Enumerated
   @Column(name = "reply_type")
   public JmsReplyType getReplyType() {
      return this._replyType == null ? JmsReplyType.AUTOMATIC : this._replyType;
   }

   public void setReplyType(JmsReplyType var1) {
      this.checkLocked();
      this._replyType = var1;
   }

   @RbacAttribute
   @Pattern(regexp = ".*?[^\\p{Space}].*")
   @Size(max = 128)
   @Column(name = "reply_to_queue_name", length = 128)
   public String getReplyToQueueName() {
      return this.replyToQueueName;
   }

   public void setReplyToQueueName(String var1) {
      this.checkLocked();
      this.replyToQueueName = var1;
   }

   @Enumerated(EnumType.STRING)
   @Column(name = "outbound_message_type")
   public JmsOutboundMessageType getOutboundMessageType() {
      return this.outboundMessageType;
   }

   public void setOutboundMessageType(JmsOutboundMessageType var1) {
      this.checkLocked();
      if (var1 == null) {
         var1 = JmsOutboundMessageType.AUTOMATIC;
      }

      this.outboundMessageType = var1;
   }

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

   public void setDisabled(boolean var1) {
      this.checkLocked();
      this.disabled = var1;
   }

   @Column(name = "use_message_id_for_correlation")
   public boolean isUseMessageIdForCorrelation() {
      return this.useMessageIdForCorrelation;
   }

   public void setUseMessageIdForCorrelation(boolean var1) {
      this.checkLocked();
      this.useMessageIdForCorrelation = var1;
   }

   @RbacAttribute(displayNameIdentifier = "jms.template")
   @Column(name = "is_template")
   public boolean isTemplate() {
      return this.template;
   }

   public void setTemplate(boolean var1) {
      this.checkLocked();
      this.template = var1;
   }

   @Column(name = "request_max_size", nullable = false)
   public long getRequestMaxSize() {
      return this.requestMaxSize;
   }

   public void setRequestMaxSize(long var1) {
      this.checkLocked();
      this.requestMaxSize = var1;
   }

   @Override
   public String toString() {
      String var10000 = String.valueOf(this._connectionGoid);
      String[] var1 = b;
      return var1[2] + var10000 + var1[0] + this._name + var1[1];
   }

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

   static {
      String[] var5 = new String[3];
      int var3 = 0;
      String var2 = "F\u000ej7I+[F\u0003F\u0001:\u001dXdi%a \u0002\u0014Am8Pn\u0005\u000b@j3G:\u000f\u000b@C9M*[F";
      int var4 = "F\u000ej7I+[F\u0003F\u0001:\u001dXdi%a \u0002\u0014Am8Pn\u0005\u000b@j3G:\u000f\u000b@C9M*[F".length();
      char var1 = '\b';
      int var0 = -1;

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

         var1 = var2.charAt(var0);
      }
   }

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

      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 -> 9;
            case 1 -> 67;
            case 2 -> 105;
            case 3 -> 59;
            case 4 -> 73;
            case 5 -> 35;
            default -> 11;
         });
      }

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

   public interface StandardValidationGroup {
   }
}
