package com.airlock.iam.saml2.application.configuration.assertion.attribute;

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.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "A SAML 2.0 attribute containing the representer's username.", displayName = "Representer ID SAML 2.0 Attribute")
@PluginLicenseRestriction(moduleAffiliation = "SamlIdp")
public class RepresenterIdAttributeConfig extends SamlIdpAttributeConfigWithNameFormat implements SamlFlowIdpAttributeConfig {
   @StringProperty(
      displayName = "Attribute Name",
      description = "The name of the attribute to add to the assertion. If there is no representer username, the attribute will not be included in the assertion.",
      exampleValues = "Representer",
      optional = false
   )
   private String samlAttributeName;

   public RepresenterIdAttributeConfig(String samlAttributeName, String nameFormat) {
      super(nameFormat);
      this.samlAttributeName = samlAttributeName;
   }

   @Override
   public String getSamlAttributeName() {
      return this.samlAttributeName;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class RepresenterIdAttributeConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String samlAttributeName;
      @SuppressFBWarnings(justification = "generated code")
      private String nameFormat;

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

      @SuppressFBWarnings(justification = "generated code")
      public RepresenterIdAttributeConfig.RepresenterIdAttributeConfigBuilder samlAttributeName(String samlAttributeName) {
         this.samlAttributeName = samlAttributeName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RepresenterIdAttributeConfig.RepresenterIdAttributeConfigBuilder nameFormat(String nameFormat) {
         this.nameFormat = nameFormat;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RepresenterIdAttributeConfig build() {
         return new RepresenterIdAttributeConfig(this.samlAttributeName, this.nameFormat);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RepresenterIdAttributeConfig.RepresenterIdAttributeConfigBuilder(samlAttributeName="
            + this.samlAttributeName
            + ", nameFormat="
            + this.nameFormat
            + ")";
      }
   }
}
