package com.airlock.iam.ssi.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.step.AbstractInteractiveFlowStepConfig;
import com.airlock.iam.flow.api.application.configuration.step.InteractiveGotoTargetConfig;
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.plugin.api.annotation.config.Groups;
import com.airlock.iam.plugin.api.annotation.config.NextActions;
import com.airlock.iam.plugin.api.annotation.license.PluginLicenseRestriction;
import com.airlock.iam.plugin.api.annotation.property.GroupProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginListProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import com.airlock.iam.ssi.application.configuration.SsiAttributeMapping;
import com.airlock.iam.ssi.application.configuration.SsiServiceConfig;
import com.airlock.iam.ssi.domain.model.step.SsiIssuanceStep;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;

@PluginLicenseRestriction(moduleAffiliation = "AirlockIAM")
@NextActions(SsiIssuanceStep.SsiIssuanceActions.class)
@Groups(openGroups = "Basic Settings", groupSequence = {"Basic Settings", "Tags/Guards", "Flow Control", "Advanced Settings"})
public abstract class AbstractSsiIssuanceStepConfig extends AbstractInteractiveFlowStepConfig {
   @PluginProperty(description = "The SSI service to be used by this step.", optional = false)
   @GroupProperty(groupIdentifier = "Basic Settings")
   private SsiServiceConfig service;
   @StringProperty(
      description = "Identifier of the schema for issuing the credential.",
      displayName = "Credential Schema Name",
      exampleValues = "Person with Age Check",
      optional = false
   )
   @GroupProperty(groupIdentifier = "Basic Settings")
   private String credentialSchemaName;
   @PluginListProperty(
      description = "Value Provider for issuing credentials. All value map providers are applied in the sequence they are configured.\nIf the same key is defined multiple times the latter overwrites the previous values.\nThe value providers are used in 'Attribute Mappings' to define the attribute values.",
      optional = false
   )
   @GroupProperty(groupIdentifier = "Basic Settings")
   private List<ValueMapProviderConfig> valueProviders;
   @PluginListProperty(
      description = "<p>Specifies the correspondences between all attribute names of the schema and the keys used for obtaining the value from the 'Value Providers'.\nAll values must be string values. Non-string values (e.g. a birthdate) can be transformed to strings by using value providers suited to the task.</p>\n<p>Note that for each attribute, a non-null value must be provided by a value provider, or else the step fails.</p>",
      optional = false
   )
   @GroupProperty(groupIdentifier = "Basic Settings")
   private List<SsiAttributeMapping> attributeMappings;

   protected AbstractSsiIssuanceStepConfig(
      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,
      SsiServiceConfig service,
      String credentialSchemaName,
      List<ValueMapProviderConfig> valueProviders,
      List<SsiAttributeMapping> attributeMappings
   ) {
      super(
         skipCondition,
         preCondition,
         requiresActivation,
         tagsOnSuccess,
         stepId,
         interactiveGotoTargets,
         dynamicStepActivations,
         onFailureGotos,
         customResponseAttributes,
         customFailureResponseAttributes
      );
      this.service = service;
      this.credentialSchemaName = credentialSchemaName;
      this.valueProviders = valueProviders;
      this.attributeMappings = attributeMappings;
   }

   public SsiServiceConfig getService() {
      return this.service;
   }

   public String getCredentialSchemaName() {
      return this.credentialSchemaName;
   }

   public List<ValueMapProviderConfig> getValueProviders() {
      return this.valueProviders;
   }

   public List<SsiAttributeMapping> getAttributeMappings() {
      return this.attributeMappings;
   }

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