package com.airlock.iam.techclientreg.application.configuration.registration;

import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.license.PluginLicenseRestriction;
import com.airlock.iam.plugin.api.annotation.property.BooleanProperty;
import com.airlock.iam.plugin.api.annotation.property.RegexProperty;
import com.airlock.iam.techclientreg.api.application.configuration.oauth2.OAuth2ClientMetadataProcessorConfig;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.regex.Pattern;

@Plugin(
   description = "Processes the \"contacts\" metadata attribute. The values are taken from the request as long as they match the configured regular expression and don't exceed the length limits imposed by the database.",
   displayName = "Contacts Processor"
)
@PluginLicenseRestriction(moduleAffiliation = "TechClientRegistration")
public class ContactsProcessorConfig implements OAuth2ClientMetadataProcessorConfig {
   @RegexProperty(
      description = "Regex limiting the contacts values provided by the client. Typically email addresses.",
      defaultValue = "[a-zA-Z0-9 _.@-]+",
      optional = true
   )
   private Pattern allowedContacts;
   @BooleanProperty(
      description = "If the attribute is mandatory a <em>valid</em> value is required, or else an error is returned. If it is not mandatory, invalid values are silently ignored.",
      optional = true,
      defaultValue = "true"
   )
   private boolean mandatory;

   public Pattern getAllowedContacts() {
      return this.allowedContacts;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public ContactsProcessorConfig(Pattern allowedContacts, boolean mandatory) {
      this.allowedContacts = allowedContacts;
      this.mandatory = mandatory;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class ContactsProcessorConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedContacts;
      @SuppressFBWarnings(justification = "generated code")
      private boolean mandatory;

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

      @SuppressFBWarnings(justification = "generated code")
      public ContactsProcessorConfig.ContactsProcessorConfigBuilder allowedContacts(Pattern allowedContacts) {
         this.allowedContacts = allowedContacts;
         return this;
      }

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

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "ContactsProcessorConfig.ContactsProcessorConfigBuilder(allowedContacts=" + this.allowedContacts + ", mandatory=" + this.mandatory + ")";
      }
   }
}
