package com.airlock.iam.transactionapproval.infrastructure.factory;

import com.airlock.iam.base.api.infrastructure.plugin.ModuleForConfig;
import com.airlock.iam.flow.api.domain.model.session.FlowSession;
import com.airlock.iam.flow.infrastructure.step.StepSessionModuleHelper;
import com.airlock.iam.flow.shared.application.configuration.selection.SelectionStepConfig;
import com.airlock.iam.flow.shared.domain.model.selection.step.LastSelectionSettings;
import com.airlock.iam.flow.shared.domain.model.selection.step.SelectionSettings;
import com.airlock.iam.flow.shared.domain.model.selection.step.SelectionStepSession;
import com.airlock.iam.flow.shared.infrastructure.factory.SelectionSettingsFactory;
import com.google.inject.Exposed;
import com.google.inject.PrivateModule;
import com.google.inject.Provides;
import java.util.Optional;

@ModuleForConfig(SelectionStepConfig.class)
public final class TransactionApprovalSelectionStepModule extends PrivateModule {
   @Exposed
   @Provides
   SelectionSettings provideSelectionSettings(SelectionStepConfig config) {
      return SelectionSettingsFactory.createSelectionSettings(config);
   }

   @Exposed
   @Provides
   Optional<LastSelectionSettings> provideLastSelectionSettings(SelectionStepConfig config) {
      return SelectionSettingsFactory.createLastSelectionSettings(config.getStepId(), config.getLastSelectionRepositoryConfig());
   }

   @Exposed
   @Provides
   SelectionStepSession provideSelectionStepSession(FlowSession flowSession) {
      return (SelectionStepSession)StepSessionModuleHelper.retrieveStepSession(flowSession, SelectionStepSession.class);
   }

   protected void configure() {
   }
}
