package at.procon.eventhub.processing.eventprocessing.module;

import at.procon.eventhub.processing.eventprocessing.plan.RuntimeProcessingModuleDescriptorDto;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

abstract class AbstractDriverWorkingTimePhaseModule implements RuntimeProcessingModule {

    private final String moduleKey;
    private final String displayName;
    private final String description;
    private final String engine;
    private final Set<String> outputTypes;

    protected AbstractDriverWorkingTimePhaseModule(
            String moduleKey,
            String displayName,
            String description,
            String engine,
            Set<String> outputTypes
    ) {
        this.moduleKey = moduleKey;
        this.displayName = displayName;
        this.description = description;
        this.engine = engine;
        this.outputTypes = outputTypes == null ? Set.of() : Set.copyOf(outputTypes);
    }

    @Override
    public String moduleKey() {
        return moduleKey;
    }

    @Override
    public RuntimeProcessingModuleDescriptorDto descriptor() {
        return new RuntimeProcessingModuleDescriptorDto(
                moduleKey,
                displayName,
                description,
                engine,
                outputTypes
        );
    }

    @Override
    public RuntimeProcessingModuleResult execute(RuntimeProcessingModuleContext context) {
        Map<String, Object> metadata = new LinkedHashMap<>();
        metadata.put("executionModel", "delegated");
        metadata.put("delegatedTo", DriverWorkingTimeModuleKeys.DRIVING_DERIVED_PROJECTIONS);
        metadata.put("note", "This logical module is currently executed inside the driver-working-time derived projections adapter. It is registered separately so it can be split into a standalone EPL/Java module without changing the processing plan contract.");
        return new RuntimeProcessingModuleResult(
                moduleKey,
                RuntimeProcessingModuleStatus.SUCCESS,
                null,
                metadata,
                java.util.List.of()
        );
    }
}
