package com.airlock.iam.common.application.configuration.validation;

import com.airlock.iam.common.api.application.configuration.validation.StringValidatorConfig;
import com.airlock.iam.common.api.application.configuration.validation.UsernameValidatorConfig;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.IntegerProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "<p>Validator to ensure that the provided string value is an email address.</p>\n<ul>\n<li>If no string is specified, the corresponding error type is <code>REQUIRED</code>.</li>\n<li>If the string is not a valid email address, the corresponding error type is <code>WRONG_FORMAT</code>.</li>\n<li>If the string exceeds the maximum length, the corresponding error type is <code>MAX_LENGTH</code>.</li>\n</ul>",
   displayName = "Email Address Validator"
)
public final class EmailAddressValidatorConfig implements StringValidatorConfig, UsernameValidatorConfig {
   public static final String EMAIL_ADDRESS_VALIDATOR_DISPLAY_NAME = "Email Address Validator";
   public static final String EMAIL_VALIDATOR_MAX_LENGTH_DESCRIPTION = "Maximum length of email addresses. 100 characters is the default IAM email database field limit. IETF accepted errata against RFC 3696 allow up to 254 characters.";
   @IntegerProperty(
      description = "Maximum length of email addresses. 100 characters is the default IAM email database field limit. IETF accepted errata against RFC 3696 allow up to 254 characters.",
      optional = true,
      defaultValue = 100,
      exampleValues = {10, 100},
      maxValue = 254
   )
   private int maximumLength;

   public int getMaximumLength() {
      return this.maximumLength;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public EmailAddressValidatorConfig(int maximumLength) {
      this.maximumLength = maximumLength;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class EmailAddressValidatorConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private int maximumLength;

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

      @SuppressFBWarnings(justification = "generated code")
      public EmailAddressValidatorConfig.EmailAddressValidatorConfigBuilder maximumLength(int maximumLength) {
         this.maximumLength = maximumLength;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public EmailAddressValidatorConfig build() {
         return new EmailAddressValidatorConfig(this.maximumLength);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "EmailAddressValidatorConfig.EmailAddressValidatorConfigBuilder(maximumLength=" + this.maximumLength + ")";
      }
   }
}
