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

import com.airlock.iam.flow.api.application.configuration.dynamicactivation.DynamicStepActivationConfig;
import com.airlock.iam.flow.api.application.configuration.selection.FlowConditionConfig;
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.api.domain.model.flowcontrol.InteractiveGotoTarget;
import com.airlock.iam.plugin.api.annotation.property.GroupProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginListProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public abstract class AbstractInteractiveFlowStepConfig extends AbstractFlowStepConfig {
   @PluginListProperty(
      description = "Manually selectable Goto targets. These are steps to which the user can chose to jump when this is the current flow step.",
      optional = true,
      minElements = 1
   )
   @GroupProperty(groupIdentifier = "Flow Control")
   private List<InteractiveGotoTargetConfig> interactiveGotoTargets;
   public static final String INTERACTIVE_GOTO_TARGETS_FIELD = "interactiveGotoTargets";
   @PluginListProperty(description = "Steps that can be dynamically activated while in this step.", optional = true, minElements = 1)
   @GroupProperty(groupIdentifier = "Flow Control")
   private List<DynamicStepActivationConfig> dynamicStepActivations;
   public static final String DYNAMIC_STEP_ACTIVATIONS_FIELD = "dynamicStepActivations";

   protected AbstractInteractiveFlowStepConfig(
      FlowConditionConfig skipCondition,
      FlowConditionConfig preCondition,
      boolean requiresActivation,
      List<TagConfig> tagsOnSuccess,
      @Nullable StepIdConfig stepId,
      List<InteractiveGotoTargetConfig> interactiveGotoTargets,
      List<DynamicStepActivationConfig> dynamicStepActivations,
      Map<String, StepIdConfig> onFailureGotos,
      List<ValueMapProviderConfig> customResponseAttributes,
      List<ValueMapProviderConfig> customFailureResponseAttributes
   ) {
      super(skipCondition, preCondition, requiresActivation, tagsOnSuccess, stepId, onFailureGotos, customResponseAttributes, customFailureResponseAttributes);
      this.interactiveGotoTargets = interactiveGotoTargets;
      this.dynamicStepActivations = dynamicStepActivations;
   }

   @Override
   public List<InteractiveGotoTarget> getInteractiveGotoTargets() {
      return this.interactiveGotoTargets.stream().map(InteractiveGotoTargetConfig::getTarget).collect(Collectors.toList());
   }

   @Override
   public List<DynamicStepActivationConfig> getDynamicStepActivationConfigs() {
      return this.dynamicStepActivations;
   }

   public List<DynamicStepActivationConfig> getDynamicStepActivations() {
      return this.dynamicStepActivations;
   }

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