package com.airlock.iam.login.application.configuration.targetapp;

import com.airlock.iam.login.domain.model.targetapp.StaticWafCredentialProvider;
import com.airlock.iam.login.domain.model.targetapp.WafCredentialProviderTimeouts;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "Provides a static Airlock Gateway role.", displayName = "Static Gateway Role")
public final class StaticWafCredentialProviderConfig extends WafCredentialProviderTimeouts implements WafCredentialProviderConfig {
   @StringProperty(
      description = "A role with this name will be added to the Airlock Gateway session.",
      displayName = "Gateway Role",
      optional = false,
      maxLength = 50,
      validationRegex = "[a-zA-Z0-9_.\\-]+"
   )
   private String airlockGatewayRole;

   private StaticWafCredentialProviderConfig(Integer idleTimeout, Integer lifetime, String airlockGatewayRole) {
      super(idleTimeout, lifetime);
      this.airlockGatewayRole = airlockGatewayRole;
   }

   public StaticWafCredentialProvider.StaticWafCredentialProviderConfiguration getConfiguration() {
      return StaticWafCredentialProvider.StaticWafCredentialProviderConfiguration.builder(this.airlockGatewayRole)
         .idleTimeout(this.getIdleTimeout())
         .lifetime(this.getLifetime())
         .build();
   }

   public String getAirlockGatewayRole() {
      return this.airlockGatewayRole;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static StaticWafCredentialProviderConfig.StaticWafCredentialProviderConfigBuilder builder() {
      return new StaticWafCredentialProviderConfig.StaticWafCredentialProviderConfigBuilder();
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class StaticWafCredentialProviderConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Integer idleTimeout;
      @SuppressFBWarnings(justification = "generated code")
      private Integer lifetime;
      @SuppressFBWarnings(justification = "generated code")
      private String airlockGatewayRole;

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

      @SuppressFBWarnings(justification = "generated code")
      public StaticWafCredentialProviderConfig.StaticWafCredentialProviderConfigBuilder idleTimeout(Integer idleTimeout) {
         this.idleTimeout = idleTimeout;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StaticWafCredentialProviderConfig.StaticWafCredentialProviderConfigBuilder lifetime(Integer lifetime) {
         this.lifetime = lifetime;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StaticWafCredentialProviderConfig.StaticWafCredentialProviderConfigBuilder airlockGatewayRole(String airlockGatewayRole) {
         this.airlockGatewayRole = airlockGatewayRole;
         return this;
      }

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

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