package com.airlock.iam.saml2.application.configuration.idp;

import com.airlock.iam.flow.shared.application.configuration.uitenantid.UiTenantIdRuleConfig;
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.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 SAML 2.0 SP entity ID of the issuer for an SP-initiated\nrequest on IAM as IdP matches a regex pattern.",
   displayName = "SAML 2.0 SP Entity ID Pattern UI Tenant ID Rule"
)
@PluginLicenseRestriction(moduleAffiliation = "SamlIdp")
public final class Saml2SpEntityIdPatternUiTenantIdRuleConfig implements UiTenantIdRuleConfig {
   @RegexProperty(
      displayName = "SAML 2.0 SP Entity ID Pattern",
      description = "If the SAML 2.0 SP entity ID of the issuer matches this pattern, the UI tenant ID will be set to the value of UI Tenant ID Value.",
      exampleValues = {".*", ".*-admin", "(.*)@mail\\.com"},
      optional = false
   )
   private Pattern spEntityIdPattern;
   private static final String SP_ENTITY_ID_PATTERN_DISPLAY_NAME = "SAML 2.0 SP Entity ID Pattern";
   @StringProperty(
      displayName = "UI Tenant ID Value",
      description = "If the SAML 2.0 SP entity ID of the issuer matches SAML 2.0 SP Entity ID Pattern, the UI tenant ID will be set to the value configured by this plugin. This replacement pattern may contain back-references to the pattern configured in SAML 2.0 SP Entity ID Pattern.",
      exampleValues = {"$1", "fixed-value", "tenant-id-$1"},
      optional = false
   )
   private String uiTenantIdValue;
   private static final String UI_TENANT_ID_VALUE_DISPLAY_NAME = "UI Tenant ID Value";

   public Pattern getSpEntityIdPattern() {
      return this.spEntityIdPattern;
   }

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

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

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

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpEntityIdPatternUiTenantIdRuleConfig.Saml2SpEntityIdPatternUiTenantIdRuleConfigBuilder spEntityIdPattern(Pattern spEntityIdPattern) {
         this.spEntityIdPattern = spEntityIdPattern;
         return this;
      }

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

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Saml2SpEntityIdPatternUiTenantIdRuleConfig.Saml2SpEntityIdPatternUiTenantIdRuleConfigBuilder(spEntityIdPattern="
            + this.spEntityIdPattern
            + ", uiTenantIdValue="
            + this.uiTenantIdValue
            + ")";
      }
   }
}
