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

import com.airlock.iam.common.domain.model.user.profileitems.InternationalPhoneNumberProfileItemLogic;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.EnumProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "Plugin to hold a configurable user profile item of type international phone number. <p>Phone numbers must be entered in international format. Phone numbers in international format start with a plus sign (+) and the country code. When parsing the phone number, punctuation and white-space as well as any text before the number is ignored (for example, a leading \"Tel: \"). To persist the phone number, it is formatted according to the ITU-T phone number format E.164.</p>This profile item will be represented as a text input field and its value is added to the user's context data, provided that the property name matches the property name in the configured user data."
)
public class InternationalPhoneNumberUserProfileItemConfig extends UserProfileItemConfigBase {
   @EnumProperty(
      description = "This property controls the level of validation that is performed.<ul>  <li><b>Default</b>: Full validation of a phone number in international format using length and prefix information. Verifies whether the parsed, canonicalised number is valid. It is not verified, whether a particular series of digits entered by the user can actually be dialled from the region provided. For example, the number +41 (0) 78 927 2696 can be parsed into a number with country code '41' and national significant number '789272696'. This is valid, while the original string cannot be dialled.</li>  <li><b>Lenient</b>: Quickly guesses whether a number is a possible phone number by using only the length information. So, validation is performed more lenient. In particular, phone numbers that have the correct lenght but may otherwise be invalid (for example, because the carrier code is invalid) are considered valid. Phone numbers must still be in international format with valid country codes.</li>  <li><b>Minimal</b>: This is the most lenient form of validation. All inputs that can be parsed to a phone number are accepted. For example, phone numbers that are otherwise considered too short or too long up (but only to a certain extent) are accepted. Phone numbers must still be in international format with valid country codes.</li></ul>",
      optional = true,
      defaultValue = "DEFAULT"
   )
   private InternationalPhoneNumberProfileItemLogic.ValidationLevel validationLevel;

   public InternationalPhoneNumberUserProfileItemConfig(
      long formFieldNr,
      String stringResourceKey,
      String propertyName,
      boolean optional,
      boolean modifiable,
      boolean validateOnlyChangedValues,
      boolean sortable,
      InternationalPhoneNumberProfileItemLogic.ValidationLevel validationLevel
   ) {
      super(stringResourceKey, propertyName, optional, modifiable, validateOnlyChangedValues, sortable);
      this.validationLevel = validationLevel;
   }

   public InternationalPhoneNumberProfileItemLogic getProfileItemLogic() {
      return InternationalPhoneNumberProfileItemLogic.builder(this.validationLevel)
         .optional(this.isOptional())
         .modifiable(this.isModifiable())
         .validateOnlyChangedValues(this.isValidateOnlyChangedValues())
         .build();
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class InternationalPhoneNumberUserProfileItemConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private long formFieldNr;
      @SuppressFBWarnings(justification = "generated code")
      private String stringResourceKey;
      @SuppressFBWarnings(justification = "generated code")
      private String propertyName;
      @SuppressFBWarnings(justification = "generated code")
      private boolean optional;
      @SuppressFBWarnings(justification = "generated code")
      private boolean modifiable;
      @SuppressFBWarnings(justification = "generated code")
      private boolean validateOnlyChangedValues;
      @SuppressFBWarnings(justification = "generated code")
      private boolean sortable;
      @SuppressFBWarnings(justification = "generated code")
      private InternationalPhoneNumberProfileItemLogic.ValidationLevel validationLevel;

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

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder formFieldNr(long formFieldNr) {
         this.formFieldNr = formFieldNr;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder stringResourceKey(String stringResourceKey) {
         this.stringResourceKey = stringResourceKey;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder propertyName(String propertyName) {
         this.propertyName = propertyName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder optional(boolean optional) {
         this.optional = optional;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder modifiable(boolean modifiable) {
         this.modifiable = modifiable;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder validateOnlyChangedValues(
         boolean validateOnlyChangedValues
      ) {
         this.validateOnlyChangedValues = validateOnlyChangedValues;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder sortable(boolean sortable) {
         this.sortable = sortable;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder validationLevel(
         InternationalPhoneNumberProfileItemLogic.ValidationLevel validationLevel
      ) {
         this.validationLevel = validationLevel;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InternationalPhoneNumberUserProfileItemConfig build() {
         return new InternationalPhoneNumberUserProfileItemConfig(
            this.formFieldNr,
            this.stringResourceKey,
            this.propertyName,
            this.optional,
            this.modifiable,
            this.validateOnlyChangedValues,
            this.sortable,
            this.validationLevel
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "InternationalPhoneNumberUserProfileItemConfig.InternationalPhoneNumberUserProfileItemConfigBuilder(formFieldNr="
            + this.formFieldNr
            + ", stringResourceKey="
            + this.stringResourceKey
            + ", propertyName="
            + this.propertyName
            + ", optional="
            + this.optional
            + ", modifiable="
            + this.modifiable
            + ", validateOnlyChangedValues="
            + this.validateOnlyChangedValues
            + ", sortable="
            + this.sortable
            + ", validationLevel="
            + this.validationLevel
            + ")";
      }
   }
}
