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

@Plugin(
   description = "Excludes users that have exceeded the allowed number of unlocks (configurable in the \"Public Self-Service Flow Settings\"). If no maximum number of unlocks is configured, this restriction is never violated.",
   displayName = "Too Many Unlocks Restriction"
)
public final class TooManyUnlocksRestrictionConfig implements InternalPublicSelfServiceRestrictionConfig {
   public static final String TOO_MANY_UNLOCKS_RESTRICTION_DISPLAY_NAME = "Too Many Unlocks Restriction";
   @BooleanProperty(
      description = "<p>If enabled, the User Identification Step always returns a specific error code in case this restriction is violated.</p><p>If no restrictions are configured to provide feedback, a flow can also be started for users violating one or more restrictions and the flow will advance to the user identity verification step in stealth mode. In this mode, the initial behavior of the step is the same as for unrestricted users (e.g. an mTAN OTP is required), but all responses are rejected as if they were incorrect. This behavior prevents restricted users from ever proceeding further in the flow and thus offers protection against user enumeration. Please refer to the documentation for more details.</p><p>Irrespective of this settings, once the identity verification step is passed, restriction are always checked before and after each method call and violations are always reported.</p><p><b>Security notice:</b> Enabling this feature might allow a client to determine whether certain users exist in the system.</p>",
      optional = true,
      defaultValue = "false"
   )
   private boolean enableFeedback;

   public boolean isEnableFeedback() {
      return this.enableFeedback;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public TooManyUnlocksRestrictionConfig(boolean enableFeedback) {
      this.enableFeedback = enableFeedback;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class TooManyUnlocksRestrictionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private boolean enableFeedback;

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

      @SuppressFBWarnings(justification = "generated code")
      public TooManyUnlocksRestrictionConfig.TooManyUnlocksRestrictionConfigBuilder enableFeedback(boolean enableFeedback) {
         this.enableFeedback = enableFeedback;
         return this;
      }

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "TooManyUnlocksRestrictionConfig.TooManyUnlocksRestrictionConfigBuilder(enableFeedback=" + this.enableFeedback + ")";
      }
   }
}
