package com.airlock.iam.flow.shared.application.configuration.valueprovider;

import com.airlock.iam.common.api.application.configuration.valueprovider.StringValueProviderConfig;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.BooleanProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;

@Plugin(
   description = "A value provider that loads the String value associated with the configured key from the 'Generic Strings Session Attribute'.<br>Those attributes are a generic way to store custom string values in the session. They are empty unless populated by custom code or by configuring a \"SAML 2.0 Assertion String Attribute Importer\" on the SAML 2.0 service provider."
)
public final class GenericSessionAttributeStringProviderConfig implements StringValueProviderConfig {
   @StringProperty(description = "The key in the 'Generic Strings Session Attribute' for which the value should be provided.", optional = false)
   private String key;
   @StringProperty(
      description = "An optional default value to be provided if the attribute container contains no value for the configured key.",
      optional = true
   )
   private String defaultValue;
   @BooleanProperty(
      description = "If this flag is set and the final value (also considering the optional default value) evaluates to <tt>null</tt>, an exception is thrown. Otherwise, <tt>null</tt> is returned.",
      defaultValue = "false",
      optional = true
   )
   private boolean failIfNull;

   public String getKey() {
      return this.key;
   }

   @Nullable
   public String getDefaultValue() {
      return this.defaultValue;
   }

   public boolean isFailIfNull() {
      return this.failIfNull;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public GenericSessionAttributeStringProviderConfig(String key, String defaultValue, boolean failIfNull) {
      this.key = key;
      this.defaultValue = defaultValue;
      this.failIfNull = failIfNull;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class GenericSessionAttributeStringProviderConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String key;
      @SuppressFBWarnings(justification = "generated code")
      private String defaultValue;
      @SuppressFBWarnings(justification = "generated code")
      private boolean failIfNull;

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

      @SuppressFBWarnings(justification = "generated code")
      public GenericSessionAttributeStringProviderConfig.GenericSessionAttributeStringProviderConfigBuilder key(String key) {
         this.key = key;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public GenericSessionAttributeStringProviderConfig.GenericSessionAttributeStringProviderConfigBuilder defaultValue(String defaultValue) {
         this.defaultValue = defaultValue;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public GenericSessionAttributeStringProviderConfig.GenericSessionAttributeStringProviderConfigBuilder failIfNull(boolean failIfNull) {
         this.failIfNull = failIfNull;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public GenericSessionAttributeStringProviderConfig build() {
         return new GenericSessionAttributeStringProviderConfig(this.key, this.defaultValue, this.failIfNull);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "GenericSessionAttributeStringProviderConfig.GenericSessionAttributeStringProviderConfigBuilder(key="
            + this.key
            + ", defaultValue="
            + this.defaultValue
            + ", failIfNull="
            + this.failIfNull
            + ")";
      }
   }
}
