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 \"client_name\" metadata attribute. The value is taken from the request as long as it matches the configured regular expression and doesn't exceed the length limit imposed by the database.<br>If not configured, no \"client_name\" is stored, and the client is simply displayed as \"DCR OAuth 2.0 Client\".",
   displayName = "Client Name Processor"
)
@PluginLicenseRestriction(moduleAffiliation = "TechClientRegistration")
public class ClientNameProcessorConfig implements OAuth2ClientMetadataProcessorConfig {
   @RegexProperty(
      description = "Regular expression limiting the client names requested by the client.",
      exampleValues = {"[\\p{IsLatin} \\p{Punct}]+", "[a-zA-Z0-9 _.-]+"},
      defaultValue = "[a-zA-Z0-9 _.-]+",
      optional = true
   )
   private Pattern allowedValues;
   @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 = "false"
   )
   private boolean mandatory;

   public Pattern getAllowedValues() {
      return this.allowedValues;
   }

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

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

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

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public ClientNameProcessorConfig.ClientNameProcessorConfigBuilder allowedValues(Pattern allowedValues) {
         this.allowedValues = allowedValues;
         return this;
      }

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

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "ClientNameProcessorConfig.ClientNameProcessorConfigBuilder(allowedValues=" + this.allowedValues + ", mandatory=" + this.mandatory + ")";
      }
   }
}
