package com.airlock.iam.login.domain.model.targetapp;

import com.airlock.iam.common.domain.model.auth.idpropagation.WafCredentialIdleTimeout;
import com.airlock.iam.common.domain.model.auth.idpropagation.WafCredentialLifetime;
import com.airlock.iam.plugin.api.annotation.property.IntegerProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.Duration;
import java.util.Optional;

public abstract class WafCredentialProviderTimeouts {
   protected static final String ALLOWED_WAF_CREDENTIAL_PATTERN = "[a-zA-Z0-9_.\\-]+";
   protected static final int MAX_WAF_CREDENTIAL_LENGTH = 50;
   @IntegerProperty(
      displayName = "Idle Timeout [s]",
      description = "The WAF credential's idle timeout in seconds. The credential will be removed after the WAF session has been idle for this duration.",
      optional = true,
      minValue = 1,
      exampleValues = {60, 300, 3600}
   )
   private Integer idleTimeout;
   @IntegerProperty(
      displayName = "Lifetime [s]",
      description = "The WAF credential's lifetime in seconds. The credential will be removed from the WAF session after this duration.",
      optional = true,
      minValue = 1,
      exampleValues = {60, 300, 3600}
   )
   private Integer lifetime;

   public final Optional<WafCredentialLifetime> getLifetime() {
      return Optional.ofNullable(this.lifetime).map(l -> WafCredentialLifetime.lifetime(Duration.ofSeconds(l.intValue())));
   }

   public final Optional<WafCredentialIdleTimeout> getIdleTimeout() {
      return Optional.ofNullable(this.idleTimeout).map(l -> WafCredentialIdleTimeout.idleTimeout(Duration.ofSeconds(l.intValue())));
   }

   @SuppressFBWarnings(justification = "generated code")
   public WafCredentialProviderTimeouts(Integer idleTimeout, Integer lifetime) {
      this.idleTimeout = idleTimeout;
      this.lifetime = lifetime;
   }

   @SuppressFBWarnings(justification = "generated code")
   public WafCredentialProviderTimeouts() {
   }
}
