package com.airlock.iam.common.domain.model.auth.idpropagation;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.Duration;
import java.util.Optional;

public final class WafCredential {
   private final String credentialName;
   private Optional<WafCredentialTimeout> credentialTimeout;

   private WafCredential(String credentialName) {
      this.credentialName = credentialName;
      this.credentialTimeout = Optional.empty();
   }

   public static WafCredential.WafCredentialBuilder builder(String name) {
      return new WafCredential(name).toBuilder();
   }

   public String formatForWaf() {
      return this.credentialName
         + this.credentialTimeout
            .map(WafCredentialTimeout::formatForWaf)
            .orElse(
               WafCredentialTimeout.wafCredentialTimeout(WafCredentialIdleTimeout.idleTimeout(Duration.ZERO), WafCredentialLifetime.lifetime(Duration.ZERO))
                  .formatForWaf()
            );
   }

   @SuppressFBWarnings(justification = "generated code")
   public WafCredential.WafCredentialBuilder toBuilder() {
      return new WafCredential.WafCredentialBuilder().credentialName(this.credentialName).credentialTimeout(this.credentialTimeout);
   }

   @SuppressFBWarnings(justification = "generated code")
   public String getCredentialName() {
      return this.credentialName;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<WafCredentialTimeout> getCredentialTimeout() {
      return this.credentialTimeout;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof WafCredential other)) {
         return false;
      } else {
         Object this$credentialName = this.credentialName;
         Object other$credentialName = other.credentialName;
         if (this$credentialName == null ? other$credentialName == null : this$credentialName.equals(other$credentialName)) {
            Object this$credentialTimeout = this.credentialTimeout;
            Object other$credentialTimeout = other.credentialTimeout;
            return this$credentialTimeout == null ? other$credentialTimeout == null : this$credentialTimeout.equals(other$credentialTimeout);
         } else {
            return false;
         }
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      Object $credentialName = this.credentialName;
      result = result * 59 + ($credentialName == null ? 43 : $credentialName.hashCode());
      Object $credentialTimeout = this.credentialTimeout;
      return result * 59 + ($credentialTimeout == null ? 43 : $credentialTimeout.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   public WafCredential(String credentialName, Optional<WafCredentialTimeout> credentialTimeout) {
      this.credentialName = credentialName;
      this.credentialTimeout = credentialTimeout;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "WafCredential(credentialName=" + this.getCredentialName() + ", credentialTimeout=" + this.getCredentialTimeout() + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class WafCredentialBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String credentialName;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<WafCredentialTimeout> credentialTimeout;

      @SuppressFBWarnings(justification = "generated code")
      WafCredentialBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public WafCredential.WafCredentialBuilder credentialName(String credentialName) {
         this.credentialName = credentialName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public WafCredential.WafCredentialBuilder credentialTimeout(Optional<WafCredentialTimeout> credentialTimeout) {
         this.credentialTimeout = credentialTimeout;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public WafCredential build() {
         return new WafCredential(this.credentialName, this.credentialTimeout);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "WafCredential.WafCredentialBuilder(credentialName=" + this.credentialName + ", credentialTimeout=" + this.credentialTimeout + ")";
      }
   }
}
