package com.airlock.iam.flow.api.application.configuration.step;

import com.airlock.iam.flow.api.domain.model.flowcontrol.InteractiveGotoTarget;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.BooleanProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "Configuration of an interactive goto target.")
public final class InteractiveGotoTargetConfig {
   @PluginProperty(description = "The ID of the target step.", displayName = "Target Step ID", optional = false)
   private StepIdConfig targetStepId;
   public static final String INTERACTIVE_TARGET_STEP_ID_FIELD = "targetStepId";
   @BooleanProperty(
      description = "Whether the transition from the source to the target step via an interactive goto causes the source step to fail. Depending on the configured flow processors this may have different effects. For instance, in an authentication flow with default processors, failing will increment the associated failed login counter.",
      defaultValue = "false",
      optional = true
   )
   private boolean treatedAsFailure;

   public InteractiveGotoTargetConfig(StepIdConfig targetStepId) {
      this.targetStepId = targetStepId;
   }

   public InteractiveGotoTarget getTarget() {
      return new InteractiveGotoTarget(this.targetStepId.getId(), this.treatedAsFailure);
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public InteractiveGotoTargetConfig(StepIdConfig targetStepId, boolean treatedAsFailure) {
      this.targetStepId = targetStepId;
      this.treatedAsFailure = treatedAsFailure;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class InteractiveGotoTargetConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private StepIdConfig targetStepId;
      @SuppressFBWarnings(justification = "generated code")
      private boolean treatedAsFailure;

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

      @SuppressFBWarnings(justification = "generated code")
      public InteractiveGotoTargetConfig.InteractiveGotoTargetConfigBuilder targetStepId(StepIdConfig targetStepId) {
         this.targetStepId = targetStepId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InteractiveGotoTargetConfig.InteractiveGotoTargetConfigBuilder treatedAsFailure(boolean treatedAsFailure) {
         this.treatedAsFailure = treatedAsFailure;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public InteractiveGotoTargetConfig build() {
         return new InteractiveGotoTargetConfig(this.targetStepId, this.treatedAsFailure);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "InteractiveGotoTargetConfig.InteractiveGotoTargetConfigBuilder(targetStepId="
            + this.targetStepId
            + ", treatedAsFailure="
            + this.treatedAsFailure
            + ")";
      }
   }
}
