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 \"software_id\" and \"software_version\" 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 = "Software ID and Software Version Processor"
)
@PluginLicenseRestriction(moduleAffiliation = "TechClientRegistration")
public class SoftwareIdAndVersionProcessorConfig implements OAuth2ClientMetadataProcessorConfig {
   @RegexProperty(description = "Regex limiting the software_id provided by the client.", defaultValue = "[a-zA-Z0-9_.-]+", optional = true)
   private Pattern allowedIds;
   @RegexProperty(description = "Regex limiting the software_version provided by the client.", defaultValue = "[a-zA-Z0-9_.-]+", optional = true)
   private Pattern allowedVersions;
   @BooleanProperty(
      description = "If mandatory, an error is returned in case either software_id or software_version is missing or at least one doesn't match the respective configured pattern. Otherwise, both software_id and software_version are ignored and not set on the registered client.",
      optional = true,
      defaultValue = "true"
   )
   private boolean mandatory;

   public Pattern getAllowedIds() {
      return this.allowedIds;
   }

   public Pattern getAllowedVersions() {
      return this.allowedVersions;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public SoftwareIdAndVersionProcessorConfig(Pattern allowedIds, Pattern allowedVersions, boolean mandatory) {
      this.allowedIds = allowedIds;
      this.allowedVersions = allowedVersions;
      this.mandatory = mandatory;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class SoftwareIdAndVersionProcessorConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedIds;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedVersions;
      @SuppressFBWarnings(justification = "generated code")
      private boolean mandatory;

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

      @SuppressFBWarnings(justification = "generated code")
      public SoftwareIdAndVersionProcessorConfig.SoftwareIdAndVersionProcessorConfigBuilder allowedIds(Pattern allowedIds) {
         this.allowedIds = allowedIds;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public SoftwareIdAndVersionProcessorConfig.SoftwareIdAndVersionProcessorConfigBuilder allowedVersions(Pattern allowedVersions) {
         this.allowedVersions = allowedVersions;
         return this;
      }

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

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "SoftwareIdAndVersionProcessorConfig.SoftwareIdAndVersionProcessorConfigBuilder(allowedIds="
            + this.allowedIds
            + ", allowedVersions="
            + this.allowedVersions
            + ", mandatory="
            + this.mandatory
            + ")";
      }
   }
}
