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

import com.airlock.iam.flow.shared.application.configuration.valueprovider.RoleProviderConfig;
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.PluginListProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;

@Plugin(description = "A SAML 2.0 attribute containing the roles from a list of role providers.", displayName = "Roles SAML 2.0 Attribute")
@PluginLicenseRestriction(moduleAffiliation = "SamlIdp")
public class RolesFlowAttributeConfig extends SamlIdpAttributeConfigWithNameFormat implements SamlFlowIdpAttributeConfig {
   @StringProperty(
      displayName = "Attribute Name",
      description = "The name of the attribute to add to the assertion.",
      exampleValues = {"Roles", "Groups"},
      optional = false
   )
   private String samlAttributeName;
   @PluginListProperty(
      description = "Providers for the roles to add to the assertion. If the role contains a timeout, it is also included in the attribute value.",
      minElements = 1,
      optional = false
   )
   private List<RoleProviderConfig> roleProviders;

   public RolesFlowAttributeConfig(String samlAttributeName, List<RoleProviderConfig> roleProviders, String nameFormat) {
      super(nameFormat);
      this.samlAttributeName = samlAttributeName;
      this.roleProviders = roleProviders;
   }

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

   public List<RoleProviderConfig> getRoleProviders() {
      return this.roleProviders;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class RolesFlowAttributeConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String samlAttributeName;
      @SuppressFBWarnings(justification = "generated code")
      private List<RoleProviderConfig> roleProviders;
      @SuppressFBWarnings(justification = "generated code")
      private String nameFormat;

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

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

      @SuppressFBWarnings(justification = "generated code")
      public RolesFlowAttributeConfig.RolesFlowAttributeConfigBuilder roleProviders(List<RoleProviderConfig> roleProviders) {
         this.roleProviders = roleProviders;
         return this;
      }

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

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

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