package com.airlock.iam.authentication.application.configuration.migration;

import com.airlock.iam.flow.api.application.configuration.selection.FlowConditionConfig;
import com.airlock.iam.flow.api.application.configuration.step.AbstractFlowStepConfig;
import com.airlock.iam.flow.api.application.configuration.step.NonInteractiveStepConfig;
import com.airlock.iam.flow.api.application.configuration.step.StepIdConfig;
import com.airlock.iam.flow.api.application.configuration.tag.TagConfig;
import com.airlock.iam.flow.api.application.configuration.valueprovider.ValueMapProviderConfig;
import com.airlock.iam.flow.types.api.application.configuration.step.StepConfigForAuthenticationFlows;
import com.airlock.iam.plugin.api.annotation.config.Groups;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.GroupProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;

@Plugin(
   description = "A flow step to complete the migration. The step sets the \"authMethod\" field on the user to the new authentication method and clears the \"nextAuthMethod\" and \"migrationDate\" fields.",
   displayName = "Complete Migration Step"
)
@Groups(openGroups = "Basic Settings", groupSequence = {"Basic Settings", "Tags/Guards", "Flow Control"})
public class CompleteMigrationStepConfig extends AbstractFlowStepConfig implements StepConfigForAuthenticationFlows, NonInteractiveStepConfig {
   static final String COMPLETE_MIGRATION_STEP_DISPLAY_NAME = "Complete Migration Step";
   @StringProperty(
      description = "The user's authentication method is set to the configured target authentication method when the migration is completed.",
      optional = false,
      suggestedValues = {"MTAN", "CRONTO", "DEVICE_TOKEN", "MATRIX"}
   )
   @GroupProperty(groupIdentifier = "Basic Settings")
   private String targetAuthMethod;

   CompleteMigrationStepConfig(
      String targetAuthMethod,
      FlowConditionConfig skipCondition,
      FlowConditionConfig preCondition,
      boolean requiresActivation,
      List<TagConfig> tagsOnSuccess,
      @Nullable StepIdConfig stepId,
      Map<String, StepIdConfig> onFailureGotos,
      List<ValueMapProviderConfig> customResponseAttributes,
      List<ValueMapProviderConfig> customFailureResponseAttributes
   ) {
      super(skipCondition, preCondition, requiresActivation, tagsOnSuccess, stepId, onFailureGotos, customResponseAttributes, customFailureResponseAttributes);
      this.targetAuthMethod = targetAuthMethod;
   }

   public String getTargetAuthMethod() {
      return this.targetAuthMethod;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public CompleteMigrationStepConfig(String targetAuthMethod) {
      this.targetAuthMethod = targetAuthMethod;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class CompleteMigrationStepConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String targetAuthMethod;
      @SuppressFBWarnings(justification = "generated code")
      private FlowConditionConfig skipCondition;
      @SuppressFBWarnings(justification = "generated code")
      private FlowConditionConfig preCondition;
      @SuppressFBWarnings(justification = "generated code")
      private boolean requiresActivation;
      @SuppressFBWarnings(justification = "generated code")
      private List<TagConfig> tagsOnSuccess;
      @SuppressFBWarnings(justification = "generated code")
      private StepIdConfig stepId;
      @SuppressFBWarnings(justification = "generated code")
      private Map<String, StepIdConfig> onFailureGotos;
      @SuppressFBWarnings(justification = "generated code")
      private List<ValueMapProviderConfig> customResponseAttributes;
      @SuppressFBWarnings(justification = "generated code")
      private List<ValueMapProviderConfig> customFailureResponseAttributes;

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

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder targetAuthMethod(String targetAuthMethod) {
         this.targetAuthMethod = targetAuthMethod;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder skipCondition(FlowConditionConfig skipCondition) {
         this.skipCondition = skipCondition;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder preCondition(FlowConditionConfig preCondition) {
         this.preCondition = preCondition;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder requiresActivation(boolean requiresActivation) {
         this.requiresActivation = requiresActivation;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder tagsOnSuccess(List<TagConfig> tagsOnSuccess) {
         this.tagsOnSuccess = tagsOnSuccess;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder stepId(@Nullable StepIdConfig stepId) {
         this.stepId = stepId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder onFailureGotos(Map<String, StepIdConfig> onFailureGotos) {
         this.onFailureGotos = onFailureGotos;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder customResponseAttributes(List<ValueMapProviderConfig> customResponseAttributes) {
         this.customResponseAttributes = customResponseAttributes;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder customFailureResponseAttributes(
         List<ValueMapProviderConfig> customFailureResponseAttributes
      ) {
         this.customFailureResponseAttributes = customFailureResponseAttributes;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CompleteMigrationStepConfig build() {
         return new CompleteMigrationStepConfig(
            this.targetAuthMethod,
            this.skipCondition,
            this.preCondition,
            this.requiresActivation,
            this.tagsOnSuccess,
            this.stepId,
            this.onFailureGotos,
            this.customResponseAttributes,
            this.customFailureResponseAttributes
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "CompleteMigrationStepConfig.CompleteMigrationStepConfigBuilder(targetAuthMethod="
            + this.targetAuthMethod
            + ", skipCondition="
            + this.skipCondition
            + ", preCondition="
            + this.preCondition
            + ", requiresActivation="
            + this.requiresActivation
            + ", tagsOnSuccess="
            + this.tagsOnSuccess
            + ", stepId="
            + this.stepId
            + ", onFailureGotos="
            + this.onFailureGotos
            + ", customResponseAttributes="
            + this.customResponseAttributes
            + ", customFailureResponseAttributes="
            + this.customFailureResponseAttributes
            + ")";
      }
   }
}
