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_uri\", \"logo_uri\", \"policy_uri\", and \"tos_uri\" metadata attributes. 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 = "URIs Processor"
)
@PluginLicenseRestriction(moduleAffiliation = "TechClientRegistration")
public class UrisProcessorConfig implements OAuth2ClientMetadataProcessorConfig {
   @RegexProperty(
      displayName = "Allowed Client URIs",
      description = "Regex limiting the client_uri provided by the client.",
      defaultValue = "https://[a-zA-Z0-9/_.-]+",
      optional = true
   )
   private Pattern allowedClientUris;
   @RegexProperty(
      displayName = "Allowed Logo URIs",
      description = "Regex limiting the logo_uri provided by the client.",
      defaultValue = "https://[a-zA-Z0-9/_.-]+",
      optional = true
   )
   private Pattern allowedLogoUris;
   @RegexProperty(
      displayName = "Allowed Privacy Policy URIs",
      description = "Regex limiting the policy_uri provided by the client.",
      defaultValue = "https://[a-zA-Z0-9/_.-]+",
      optional = true
   )
   private Pattern allowedPolicyUris;
   @RegexProperty(
      displayName = "Allowed Terms of Service URIs",
      description = "Regex limiting the tos_uri provided by the client.",
      defaultValue = "https://[a-zA-Z0-9/_.-]+",
      optional = true
   )
   private Pattern allowedTosUris;
   @BooleanProperty(
      displayName = "Client URI mandatory",
      description = "If client_uri 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 clientUriMandatory;
   @BooleanProperty(
      displayName = "Logo URI mandatory",
      description = "If logo_uri 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 logoUriMandatory;
   @BooleanProperty(
      displayName = "Privacy Policy URI mandatory",
      description = "If policy_uri 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 policyUriMandatory;
   @BooleanProperty(
      displayName = "Terms of Service URI mandatory",
      description = "If tos_uri 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 tosUriMandatory;

   public Pattern getAllowedClientUris() {
      return this.allowedClientUris;
   }

   public Pattern getAllowedLogoUris() {
      return this.allowedLogoUris;
   }

   public Pattern getAllowedPolicyUris() {
      return this.allowedPolicyUris;
   }

   public Pattern getAllowedTosUris() {
      return this.allowedTosUris;
   }

   public boolean isClientUriMandatory() {
      return this.clientUriMandatory;
   }

   public boolean isLogoUriMandatory() {
      return this.logoUriMandatory;
   }

   public boolean isPolicyUriMandatory() {
      return this.policyUriMandatory;
   }

   public boolean isTosUriMandatory() {
      return this.tosUriMandatory;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public UrisProcessorConfig(
      Pattern allowedClientUris,
      Pattern allowedLogoUris,
      Pattern allowedPolicyUris,
      Pattern allowedTosUris,
      boolean clientUriMandatory,
      boolean logoUriMandatory,
      boolean policyUriMandatory,
      boolean tosUriMandatory
   ) {
      this.allowedClientUris = allowedClientUris;
      this.allowedLogoUris = allowedLogoUris;
      this.allowedPolicyUris = allowedPolicyUris;
      this.allowedTosUris = allowedTosUris;
      this.clientUriMandatory = clientUriMandatory;
      this.logoUriMandatory = logoUriMandatory;
      this.policyUriMandatory = policyUriMandatory;
      this.tosUriMandatory = tosUriMandatory;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class UrisProcessorConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedClientUris;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedLogoUris;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedPolicyUris;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedTosUris;
      @SuppressFBWarnings(justification = "generated code")
      private boolean clientUriMandatory;
      @SuppressFBWarnings(justification = "generated code")
      private boolean logoUriMandatory;
      @SuppressFBWarnings(justification = "generated code")
      private boolean policyUriMandatory;
      @SuppressFBWarnings(justification = "generated code")
      private boolean tosUriMandatory;

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

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder allowedClientUris(Pattern allowedClientUris) {
         this.allowedClientUris = allowedClientUris;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder allowedLogoUris(Pattern allowedLogoUris) {
         this.allowedLogoUris = allowedLogoUris;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder allowedPolicyUris(Pattern allowedPolicyUris) {
         this.allowedPolicyUris = allowedPolicyUris;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder allowedTosUris(Pattern allowedTosUris) {
         this.allowedTosUris = allowedTosUris;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder clientUriMandatory(boolean clientUriMandatory) {
         this.clientUriMandatory = clientUriMandatory;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder logoUriMandatory(boolean logoUriMandatory) {
         this.logoUriMandatory = logoUriMandatory;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder policyUriMandatory(boolean policyUriMandatory) {
         this.policyUriMandatory = policyUriMandatory;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig.UrisProcessorConfigBuilder tosUriMandatory(boolean tosUriMandatory) {
         this.tosUriMandatory = tosUriMandatory;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UrisProcessorConfig build() {
         return new UrisProcessorConfig(
            this.allowedClientUris,
            this.allowedLogoUris,
            this.allowedPolicyUris,
            this.allowedTosUris,
            this.clientUriMandatory,
            this.logoUriMandatory,
            this.policyUriMandatory,
            this.tosUriMandatory
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "UrisProcessorConfig.UrisProcessorConfigBuilder(allowedClientUris="
            + this.allowedClientUris
            + ", allowedLogoUris="
            + this.allowedLogoUris
            + ", allowedPolicyUris="
            + this.allowedPolicyUris
            + ", allowedTosUris="
            + this.allowedTosUris
            + ", clientUriMandatory="
            + this.clientUriMandatory
            + ", logoUriMandatory="
            + this.logoUriMandatory
            + ", policyUriMandatory="
            + this.policyUriMandatory
            + ", tosUriMandatory="
            + this.tosUriMandatory
            + ")";
      }
   }
}
