package com.airlock.iam.login.application.configuration.event;

import com.airlock.iam.plugin.api.annotation.property.RegexProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import java.util.regex.Pattern;

public abstract class CommonGenericStepResultSubscribedEventConfig {
   @RegexProperty(
      description = "If configured, the subscriber is only notified of events that have a step ID and whose step ID matches the defined pattern.",
      optional = true,
      displayName = "Step ID Filter"
   )
   private Pattern stepIdFilter;
   @RegexProperty(
      description = "If configured, the subscriber is only notified of events whose flow ID (or application ID in case of an authentication flow) matches the defined pattern.",
      optional = true,
      displayName = "Flow ID Filter"
   )
   private Pattern flowIdFilter;
   @StringProperty(
      description = "If configured, the subscriber is only notified of events from flows of the configured type.",
      allowedValues = {"Authentication and Authorization", "Public Self-Service", "Protected Self-Service", "User Self-Registration"},
      optional = true
   )
   private String flowTypeFilter;
   @StringProperty(
      description = "If configured, the subscriber is only notified of events if the step result is of the configured type.",
      allowedValues = {"SUCCESS", "STAY", "SKIP", "FAIL", "FAIL_RETRY", "SUBFLOW_SELECTED", "GOTO", "FAIL_GOTO", "INTERNAL_ERROR"},
      optional = true
   )
   private String resultTypeFilter;
   @RegexProperty(
      description = "If configured, the subscriber is only notified of events that have a \"next step action\" code and if this code matches the configured pattern.",
      exampleValues = {"PASSWORD_REQUIRED", ".*_REQUIRED"},
      optional = true
   )
   private Pattern nextActionFilter;
   @RegexProperty(
      description = "If configured, the subscriber is only notified of events that have an error code code and if this code matches the configured pattern.",
      exampleValues = {"USERNAME_PASSWORD_WRONG", ".*_PASSWORD_.*"},
      optional = true
   )
   private Pattern errorCodeFilter;

   public Optional<Pattern> getStepIdFilter() {
      return Optional.ofNullable(this.stepIdFilter);
   }

   public Optional<Pattern> getFlowIdFilter() {
      return Optional.ofNullable(this.flowIdFilter);
   }

   public Optional<String> getFlowTypeFilter() {
      return Optional.ofNullable(this.flowTypeFilter);
   }

   public Optional<String> getResultTypeFilter() {
      return Optional.ofNullable(this.resultTypeFilter);
   }

   public Optional<Pattern> getNextActionFilter() {
      return Optional.ofNullable(this.nextActionFilter);
   }

   public Optional<Pattern> getErrorCodeFilter() {
      return Optional.ofNullable(this.errorCodeFilter);
   }

   @SuppressFBWarnings(justification = "generated code")
   public CommonGenericStepResultSubscribedEventConfig(
      Pattern stepIdFilter, Pattern flowIdFilter, String flowTypeFilter, String resultTypeFilter, Pattern nextActionFilter, Pattern errorCodeFilter
   ) {
      this.stepIdFilter = stepIdFilter;
      this.flowIdFilter = flowIdFilter;
      this.flowTypeFilter = flowTypeFilter;
      this.resultTypeFilter = resultTypeFilter;
      this.nextActionFilter = nextActionFilter;
      this.errorCodeFilter = errorCodeFilter;
   }

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