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

import com.airlock.iam.common.api.application.configuration.validation.StringValidatorConfig;
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.IntegerProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "<p>Validator to ensure that the provided string value potentially is a phone number.</p>\n<ul>\n<li>If no string is specified, the corresponding error type is <code>REQUIRED</code>.</li>\n<li>If the string exceeds the maximum length, the corresponding error type is <code>MAX_LENGTH</code>.</li>\n<li>If the string is not a valid phone number, the corresponding error type is <code>WRONG_FORMAT</code>.</li>\n</ul>"
)
public final class PhoneNumberValidatorConfig implements StringValidatorConfig {
   @BooleanProperty(
      description = "If strict mode is enabled, the number must be in a normalized format, i.e. only consist of an optional plus sign, followed by digits. Otherwise, the number may also contain separating characters like spaces, dashes or parentheses.",
      defaultValue = "false",
      optional = true
   )
   private boolean strictMode;
   @IntegerProperty(description = "Maximum length of the phone number.", optional = true, defaultValue = 30, maxValue = 256, exampleValues = {12, 20, 30})
   private int maximumLength;

   public boolean isStrictMode() {
      return this.strictMode;
   }

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public PhoneNumberValidatorConfig(boolean strictMode, int maximumLength) {
      this.strictMode = strictMode;
      this.maximumLength = maximumLength;
   }

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

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

      @SuppressFBWarnings(justification = "generated code")
      public PhoneNumberValidatorConfig.PhoneNumberValidatorConfigBuilder strictMode(boolean strictMode) {
         this.strictMode = strictMode;
         return this;
      }

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

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "PhoneNumberValidatorConfig.PhoneNumberValidatorConfigBuilder(strictMode=" + this.strictMode + ", maximumLength=" + this.maximumLength + ")";
      }
   }
}
