package com.airlock.iam.flow.shared.application.configuration;

import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.IntegerProperty;
import com.airlock.iam.plugin.api.annotation.property.RegexProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import java.util.regex.Pattern;

@Plugin(description = "Defines a request attribute name with a value validation pattern.", displayName = "Request Attribute")
public class HttpParameterSpec {
   @StringProperty(description = "The name of the attribute (case-insensitive).", optional = false)
   private String attributeName;
   @RegexProperty(
      description = "Pattern defining valid values. Values not matching the pattern are rejected by the server. Use .* if any value is considered to be valid and should be accepted.",
      optional = true,
      defaultValue = "[a-zA-Z0-9.,:_ -]*"
   )
   private Pattern valueValidatorPattern;
   @IntegerProperty(minValue = 0, defaultValue = 30, description = "Restricts the value's maximum length.", exampleValues = {0, 5, 50}, optional = true)
   private int maxValueLength;

   public Optional<Pattern> getValueValidatorPattern() {
      return Optional.ofNullable(this.valueValidatorPattern);
   }

   public String getAttributeName() {
      return this.attributeName;
   }

   public int getMaxValueLength() {
      return this.maxValueLength;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public HttpParameterSpec(String attributeName, Pattern valueValidatorPattern, int maxValueLength) {
      this.attributeName = attributeName;
      this.valueValidatorPattern = valueValidatorPattern;
      this.maxValueLength = maxValueLength;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class HttpParameterSpecBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String attributeName;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern valueValidatorPattern;
      @SuppressFBWarnings(justification = "generated code")
      private int maxValueLength;

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

      @SuppressFBWarnings(justification = "generated code")
      public HttpParameterSpec.HttpParameterSpecBuilder attributeName(String attributeName) {
         this.attributeName = attributeName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HttpParameterSpec.HttpParameterSpecBuilder valueValidatorPattern(Pattern valueValidatorPattern) {
         this.valueValidatorPattern = valueValidatorPattern;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HttpParameterSpec.HttpParameterSpecBuilder maxValueLength(int maxValueLength) {
         this.maxValueLength = maxValueLength;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HttpParameterSpec build() {
         return new HttpParameterSpec(this.attributeName, this.valueValidatorPattern, this.maxValueLength);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "HttpParameterSpec.HttpParameterSpecBuilder(attributeName="
            + this.attributeName
            + ", valueValidatorPattern="
            + this.valueValidatorPattern
            + ", maxValueLength="
            + this.maxValueLength
            + ")";
      }
   }
}
