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

import com.airlock.iam.plugin.api.annotation.config.Groups;
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 = "Sets the UI Tenant ID to a static value if the request URL matches a regex pattern.",
   displayName = "Request URL Pattern UI Tenant ID Rule"
)
@Groups(openGroups = "Basic Settings", groupSequence = "Basic Settings")
public final class RequestUrlPatternUiTenantIdRuleConfig implements UiTenantIdRuleConfig {
   @RegexProperty(
      displayName = "Request URL Pattern",
      description = "<p>If the request URL matches this pattern, the UI Tenant ID is set to the value configured in UI Tenant ID Value.</p><p>The request URL considered here is the URL of the first request made to the IAM backend to start the flow, not the URL entered into the end-client browser.</p><p>The request URL checked against this pattern includes the protocol, host, port and path, but excludes query parameters.</p>",
      exampleValues = {".*", "https?://example\\.client\\.com/.*", ".*/rest/protected/self-service/flows/password-change/select"},
      optional = false
   )
   private Pattern requestUrlPattern;
   private static final String REQUEST_URL_PATTERN_DISPLAY_NAME = "Request URL Pattern";
   @StringProperty(
      displayName = "UI Tenant ID Value",
      description = "If the request URL matches the pattern configured in Request URL Pattern, the UI Tenant ID is set to this value.",
      optional = false,
      exampleValues = {"example-tenant-id", "exampleTenantId", "value1"}
   )
   private String uiTenantIdValue;
   private static final String UI_TENANT_ID_VALUE_DISPLAY_NAME = "UI Tenant ID Value";

   public Pattern getRequestUrlPattern() {
      return this.requestUrlPattern;
   }

   public String getUiTenantIdValue() {
      return this.uiTenantIdValue;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public RequestUrlPatternUiTenantIdRuleConfig(Pattern requestUrlPattern, String uiTenantIdValue) {
      this.requestUrlPattern = requestUrlPattern;
      this.uiTenantIdValue = uiTenantIdValue;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class RequestUrlPatternUiTenantIdRuleConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Pattern requestUrlPattern;
      @SuppressFBWarnings(justification = "generated code")
      private String uiTenantIdValue;

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

      @SuppressFBWarnings(justification = "generated code")
      public RequestUrlPatternUiTenantIdRuleConfig.RequestUrlPatternUiTenantIdRuleConfigBuilder requestUrlPattern(Pattern requestUrlPattern) {
         this.requestUrlPattern = requestUrlPattern;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RequestUrlPatternUiTenantIdRuleConfig.RequestUrlPatternUiTenantIdRuleConfigBuilder uiTenantIdValue(String uiTenantIdValue) {
         this.uiTenantIdValue = uiTenantIdValue;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RequestUrlPatternUiTenantIdRuleConfig build() {
         return new RequestUrlPatternUiTenantIdRuleConfig(this.requestUrlPattern, this.uiTenantIdValue);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RequestUrlPatternUiTenantIdRuleConfig.RequestUrlPatternUiTenantIdRuleConfigBuilder(requestUrlPattern="
            + this.requestUrlPattern
            + ", uiTenantIdValue="
            + this.uiTenantIdValue
            + ")";
      }
   }
}
