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 WafCredentialTimeout {
   private final Optional<WafCredentialIdleTimeout> idleTimeout;
   private final Optional<WafCredentialLifetime> lifetime;

   public static WafCredentialTimeout wafCredentialTimeout(WafCredentialIdleTimeout idleTimeout) {
      return new WafCredentialTimeout(Optional.of(idleTimeout), Optional.empty());
   }

   public static WafCredentialTimeout wafCredentialTimeout(WafCredentialLifetime lifetime) {
      return new WafCredentialTimeout(Optional.empty(), Optional.of(lifetime));
   }

   public static WafCredentialTimeout wafCredentialTimeout(WafCredentialIdleTimeout idleTimeout, WafCredentialLifetime lifetime) {
      return new WafCredentialTimeout(Optional.of(idleTimeout), Optional.of(lifetime));
   }

   public static WafCredentialTimeout.WafCredentialTimeoutBuilder builder(WafCredentialIdleTimeout idleTimeout) {
      return wafCredentialTimeout(idleTimeout).toBuilder();
   }

   public static Optional<WafCredentialTimeout> wafCredentialTimeout(Optional<WafCredentialIdleTimeout> idleTimeout, Optional<WafCredentialLifetime> lifetime) {
      return idleTimeout.isEmpty() && lifetime.isEmpty() ? Optional.empty() : Optional.of(new WafCredentialTimeout(idleTimeout, lifetime));
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public WafCredentialTimeout.WafCredentialTimeoutBuilder toBuilder() {
      return new WafCredentialTimeout.WafCredentialTimeoutBuilder().idleTimeout(this.idleTimeout).lifetime(this.lifetime);
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "WafCredentialTimeout(idleTimeout=" + this.getIdleTimeout() + ", lifetime=" + this.getLifetime() + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<WafCredentialIdleTimeout> getIdleTimeout() {
      return this.idleTimeout;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<WafCredentialLifetime> getLifetime() {
      return this.lifetime;
   }

   @SuppressFBWarnings(justification = "generated code")
   private WafCredentialTimeout(Optional<WafCredentialIdleTimeout> idleTimeout, Optional<WafCredentialLifetime> lifetime) {
      this.idleTimeout = idleTimeout;
      this.lifetime = lifetime;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class WafCredentialTimeoutBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Optional<WafCredentialIdleTimeout> idleTimeout;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<WafCredentialLifetime> lifetime;

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public WafCredentialTimeout build() {
         return new WafCredentialTimeout(this.idleTimeout, this.lifetime);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "WafCredentialTimeout.WafCredentialTimeoutBuilder(idleTimeout=" + this.idleTimeout + ", lifetime=" + this.lifetime + ")";
      }
   }
}
