package com.airlock.iam.publicselfservice.application.configuration.restrictions;

import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.PluginListProperty;
import com.airlock.iam.publicselfservice.api.application.configuration.PublicSelfServiceRestrictionConfig;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;

@Plugin(
   description = "<p>Custom configuration for public self-service restrictions.</p><p>See the plugin descriptions of \"Default Password Reset Restrictions\" or \"Default Self-Unlock Restrictions\" for determine reasonable sets of restrictions.</p>",
   displayName = "Custom Public Self-Service Restrictions"
)
public final class CustomPublicSelfServiceRestrictionsConfig implements PublicSelfServiceRestrictionsConfig {
   public static final String CUSTOM_PUBLIC_SELF_SERVICE_RESTRICTIONS_DISPLAY_NAME = "Custom Public Self-Service Restrictions";
   @PluginListProperty(
      description = "<p>Restrictions define which users are allowed to perform a public self-service. These restrictions are checked in the configured order and after the first restriction disallows public self-service, no further checks are performed.</p><p><b>Security Warning:</b> We recommend to use at least the restrictions provided by the \"Default Password Reset Restrictions\". Omitting these restrictions may allow public self-service for unauthorized (e.g. locked or invalid) users. The \"Nonexistent User Restriction\" is probably always needed and should be the first restriction in the list.</p>",
      optional = true,
      minElements = 1
   )
   private List<PublicSelfServiceRestrictionConfig> restrictions;

   @Override
   public List<PublicSelfServiceRestrictionConfig> getRestrictions() {
      return this.restrictions;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public CustomPublicSelfServiceRestrictionsConfig(List<PublicSelfServiceRestrictionConfig> restrictions) {
      this.restrictions = restrictions;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class CustomPublicSelfServiceRestrictionsConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private List<PublicSelfServiceRestrictionConfig> restrictions;

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

      @SuppressFBWarnings(justification = "generated code")
      public CustomPublicSelfServiceRestrictionsConfig.CustomPublicSelfServiceRestrictionsConfigBuilder restrictions(
         List<PublicSelfServiceRestrictionConfig> restrictions
      ) {
         this.restrictions = restrictions;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CustomPublicSelfServiceRestrictionsConfig build() {
         return new CustomPublicSelfServiceRestrictionsConfig(this.restrictions);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "CustomPublicSelfServiceRestrictionsConfig.CustomPublicSelfServiceRestrictionsConfigBuilder(restrictions=" + this.restrictions + ")";
      }
   }
}
