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

import com.airlock.iam.common.api.application.configuration.valueprovider.DateAndTimeValueProviderConfig;
import com.airlock.iam.core.application.configuration.contextdata.DateAndTimeContextDataItemNameConfig;
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 date and time 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 = "Date And Time Context Data Value Provider"
)
public final class ContextDataDateAndTimeValueProviderConfig implements DateAndTimeValueProviderConfig {
   @PluginProperty(description = "Context data field whose value will be returned.", optional = false)
   private DateAndTimeContextDataItemNameConfig 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 DateAndTimeContextDataItemNameConfig getContextDataField() {
      return this.contextDataField;
   }

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

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

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

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public ContextDataDateAndTimeValueProviderConfig.ContextDataDateAndTimeValueProviderConfigBuilder contextDataField(
         DateAndTimeContextDataItemNameConfig contextDataField
      ) {
         this.contextDataField = contextDataField;
         return this;
      }

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

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

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