package com.airlock.iam.common.application.configuration.valueprovider.contextdata;

import com.airlock.iam.common.api.application.configuration.valueprovider.StringValueProviderConfig;
import com.airlock.iam.common.api.application.configuration.valueprovider.UserInformationProviderConfig;
import com.airlock.iam.common.api.application.configuration.valueprovider.UsernameToPropagateProviderConfig;
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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "<p>Provides the string value contained in the specified context data item of the user.</p>\n<p>Make sure the configured context data item is also configured on the user persister.</p>",
   displayName = "String Context Data Value Provider"
)
public class ContextDataStringValueProviderConfig implements StringValueProviderConfig, UserInformationProviderConfig, UsernameToPropagateProviderConfig {
   @PluginProperty(description = "Context data field whose value will be returned.", optional = false)
   private StringContextDataItemNameConfig contextDataField;
   @BooleanProperty(
      description = "<p>If enabled, the value provided by this context data item is not allowed to be null.</p>\n<p>If this option is enabled and the context data item is null (e.g. if the configured context data is not\nconfigured on the user persister), an exception will be thrown at runtime.</p>",
      optional = true,
      defaultValue = "false"
   )
   private boolean mandatory;

   public StringContextDataItemNameConfig getContextDataField() {
      return this.contextDataField;
   }

   public boolean isMandatory() {
      return this.mandatory;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public ContextDataStringValueProviderConfig(StringContextDataItemNameConfig contextDataField, boolean mandatory) {
      this.contextDataField = contextDataField;
      this.mandatory = mandatory;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class ContextDataStringValueProviderConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private StringContextDataItemNameConfig contextDataField;
      @SuppressFBWarnings(justification = "generated code")
      private boolean mandatory;

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

      @SuppressFBWarnings(justification = "generated code")
      public ContextDataStringValueProviderConfig.ContextDataStringValueProviderConfigBuilder contextDataField(StringContextDataItemNameConfig contextDataField) {
         this.contextDataField = contextDataField;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public ContextDataStringValueProviderConfig.ContextDataStringValueProviderConfigBuilder mandatory(boolean mandatory) {
         this.mandatory = mandatory;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public ContextDataStringValueProviderConfig build() {
         return new ContextDataStringValueProviderConfig(this.contextDataField, this.mandatory);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "ContextDataStringValueProviderConfig.ContextDataStringValueProviderConfigBuilder(contextDataField="
            + this.contextDataField
            + ", mandatory="
            + this.mandatory
            + ")";
      }
   }
}
