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

import com.airlock.iam.core.application.configuration.contextdata.StringContextDataItemNameConfig;
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.PluginProperty;
import com.airlock.iam.plugin.api.annotation.property.StringListProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;
import java.util.Optional;

@Plugin(
   description = "User context data item that stores a string value out of a fixed set of allowed strings.",
   displayName = "Enumeration User Context Data Item"
)
public final class EnumContextDataItemDefinitionConfig implements ContextDataItemDefinitionConfig<String> {
   @PluginProperty(description = "The context data item in the context data.", optional = false)
   private StringContextDataItemNameConfig contextDataName;
   @BooleanProperty(
      description = "Specifies whether this context data item is required for the step to validate successfully.",
      defaultValue = "true",
      optional = true
   )
   private boolean required;
   @StringListProperty(description = "The allowed values of the context data item.", optional = false, minElements = 1, unique = true)
   private List<String> values;
   @StringProperty(
      description = "<p>The input purpose allows labeling data items using standardized values\n(see <a href=\"https://www.w3.org/TR/WCAG22/#input-purposes\" target=\"_blank\">https://www.w3.org/TR/WCAG22/#input-purposes</a>).</p>\n<p>It is rendered using the HTML attribute \"autocomplete\".\nBrowsers can use this to automatically fill input fields with data that was previously entered in other fields with the same purpose.</p><p>Note that the input purpose provided here will be used in the default Loginapp UI components and is available to\ncustom single-page applications via the REST endpoints <code>*/info/retrieve</code>.</p>\n<p>If the Loginapp UI is used with <em>configuration-based</em> 'Customized Step UIs', the input purpose has to be defined on the UI elements\n('Input UI Element', 'Drop-Down UI Element', 'Date UI Element').</p>",
      optional = true,
      suggestedValues = {"language", "sex", "honorific-prefix", "country", "country-name", "cc-type"}
   )
   private String inputPurpose;

   @Override
   public String getContextDataItemName() {
      return this.contextDataName.getContextDataName();
   }

   @Override
   public Class<String> getType() {
      return String.class;
   }

   @Override
   public boolean isRequired() {
      return this.required;
   }

   public List<String> getValues() {
      return this.values;
   }

   @Override
   public Optional<String> getInputPurpose() {
      return Optional.ofNullable(this.inputPurpose);
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public EnumContextDataItemDefinitionConfig(StringContextDataItemNameConfig contextDataName, boolean required, List<String> values, String inputPurpose) {
      this.contextDataName = contextDataName;
      this.required = required;
      this.values = values;
      this.inputPurpose = inputPurpose;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class EnumContextDataItemDefinitionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private StringContextDataItemNameConfig contextDataName;
      @SuppressFBWarnings(justification = "generated code")
      private boolean required;
      @SuppressFBWarnings(justification = "generated code")
      private List<String> values;
      @SuppressFBWarnings(justification = "generated code")
      private String inputPurpose;

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

      @SuppressFBWarnings(justification = "generated code")
      public EnumContextDataItemDefinitionConfig.EnumContextDataItemDefinitionConfigBuilder contextDataName(StringContextDataItemNameConfig contextDataName) {
         this.contextDataName = contextDataName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public EnumContextDataItemDefinitionConfig.EnumContextDataItemDefinitionConfigBuilder required(boolean required) {
         this.required = required;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public EnumContextDataItemDefinitionConfig.EnumContextDataItemDefinitionConfigBuilder values(List<String> values) {
         this.values = values;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public EnumContextDataItemDefinitionConfig.EnumContextDataItemDefinitionConfigBuilder inputPurpose(String inputPurpose) {
         this.inputPurpose = inputPurpose;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public EnumContextDataItemDefinitionConfig build() {
         return new EnumContextDataItemDefinitionConfig(this.contextDataName, this.required, this.values, this.inputPurpose);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "EnumContextDataItemDefinitionConfig.EnumContextDataItemDefinitionConfigBuilder(contextDataName="
            + this.contextDataName
            + ", required="
            + this.required
            + ", values="
            + this.values
            + ", inputPurpose="
            + this.inputPurpose
            + ")";
      }
   }
}
