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 are invalid, either because of the validity flag or the validity period.", displayName = "Invalid User Restriction")
public class InvalidUserRestrictionConfig implements InternalPublicSelfServiceRestrictionConfig {
   static final String INVALID_USER_RESTRICTION_DISPLAY_NAME = "Invalid User 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 InvalidUserRestrictionConfig.InvalidUserRestrictionConfigBuilder builder() {
      return new InvalidUserRestrictionConfig.InvalidUserRestrictionConfigBuilder();
   }

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

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

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

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

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

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

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