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

import com.airlock.iam.common.api.application.configuration.valueprovider.BooleanValueProviderConfig;
import com.airlock.iam.core.application.configuration.contextdata.BooleanContextDataItemNameConfig;
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 boolean 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 = "Boolean Context Data Value Provider"
)
public class ContextDataBooleanValueProviderConfig implements BooleanValueProviderConfig {
   @PluginProperty(description = "Context data field whose value will be returned.", optional = false)
   private BooleanContextDataItemNameConfig 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 BooleanContextDataItemNameConfig getContextDataField() {
      return this.contextDataField;
   }

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

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

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

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public ContextDataBooleanValueProviderConfig.ContextDataBooleanValueProviderConfigBuilder contextDataField(
         BooleanContextDataItemNameConfig contextDataField
      ) {
         this.contextDataField = contextDataField;
         return this;
      }

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

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

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