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.StringListProperty;
import com.airlock.iam.techclientreg.api.application.configuration.oauth2.OAuth2ClientMetadataProcessorConfig;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;

@Plugin(
   description = "Processes the \"token_endpoint_auth_method\" metadata attribute. The value is taken from the request as long as it matches the configured allowed values and doesn't exceed the length limit imposed by the database.",
   displayName = "Token Endpoint Auth Method Processor"
)
@PluginLicenseRestriction(moduleAffiliation = "TechClientRegistration")
public class TokenEndpointAuthMethodProcessorConfig implements OAuth2ClientMetadataProcessorConfig {
   @StringListProperty(
      description = "Allowed values limiting the token endpoint auth method requested by the client.",
      exampleElements = {"none", "client_secret_post", "client_secret_basic"},
      defaultValue = {"none", "client_secret_post", "client_secret_basic"},
      optional = true
   )
   private List<String> 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 List<String> getAllowedValues() {
      return this.allowedValues;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public TokenEndpointAuthMethodProcessorConfig(List<String> allowedValues, boolean mandatory) {
      this.allowedValues = allowedValues;
      this.mandatory = mandatory;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class TokenEndpointAuthMethodProcessorConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private List<String> allowedValues;
      @SuppressFBWarnings(justification = "generated code")
      private boolean mandatory;

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

      @SuppressFBWarnings(justification = "generated code")
      public TokenEndpointAuthMethodProcessorConfig.TokenEndpointAuthMethodProcessorConfigBuilder allowedValues(List<String> allowedValues) {
         this.allowedValues = allowedValues;
         return this;
      }

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

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

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