package com.airlock.iam.common.application.configuration.valueprovider;

import com.airlock.iam.common.api.application.configuration.valueprovider.StringValueProviderConfig;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
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.regex.Pattern;

@Plugin(
   description = "Provides the value of an HTTP header from the current HTTP request.\n<p>Only the current request is considered. In case the same header was set in a previous request,\nbut not the current one, the value provider will provide no value.</p>",
   displayName = "HTTP Request Header Value Provider"
)
public final class HttpRequestHeaderStringValueProviderConfig implements StringValueProviderConfig {
   @StringProperty(description = "The name of the HTTP header of which the value will be extracted from the current request.", optional = false)
   private String headerName;
   @RegexProperty(
      description = "In case a header is present, its value has to match the configured Regex pattern.\nOtherwise, no value will be returned.",
      optional = true,
      defaultValue = "[a-zA-Z0-9 ._-]+"
   )
   private Pattern allowedHeaderValuePattern;

   public String getHeaderName() {
      return this.headerName;
   }

   public Pattern getAllowedHeaderValuePattern() {
      return this.allowedHeaderValuePattern;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public HttpRequestHeaderStringValueProviderConfig(String headerName, Pattern allowedHeaderValuePattern) {
      this.headerName = headerName;
      this.allowedHeaderValuePattern = allowedHeaderValuePattern;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class HttpRequestHeaderStringValueProviderConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String headerName;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern allowedHeaderValuePattern;

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

      @SuppressFBWarnings(justification = "generated code")
      public HttpRequestHeaderStringValueProviderConfig.HttpRequestHeaderStringValueProviderConfigBuilder headerName(String headerName) {
         this.headerName = headerName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HttpRequestHeaderStringValueProviderConfig.HttpRequestHeaderStringValueProviderConfigBuilder allowedHeaderValuePattern(
         Pattern allowedHeaderValuePattern
      ) {
         this.allowedHeaderValuePattern = allowedHeaderValuePattern;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HttpRequestHeaderStringValueProviderConfig build() {
         return new HttpRequestHeaderStringValueProviderConfig(this.headerName, this.allowedHeaderValuePattern);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "HttpRequestHeaderStringValueProviderConfig.HttpRequestHeaderStringValueProviderConfigBuilder(headerName="
            + this.headerName
            + ", allowedHeaderValuePattern="
            + this.allowedHeaderValuePattern
            + ")";
      }
   }
}
