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

import at.procon.eventhub.processing.eventprocessing.dto.RuntimeEventProcessingPartitionResultDto;
import at.procon.eventhub.processing.eventprocessing.module.RuntimeProcessingModuleResult;
import at.procon.eventhub.processing.eventprocessing.partition.RuntimeEventPartitioningStrategy;
import at.procon.eventhub.processing.model.UnifiedDiscoveredVehicleRef;
import at.procon.eventhub.processing.model.UnifiedRuntimeProcessingRequest;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public record RuntimeProcessingExecutionResultDto(
        String processingPlanKey,
        List<String> executedModules,
        RuntimeEventPartitioningStrategy partitioningStrategy,
        UnifiedRuntimeProcessingRequest request,
        int inputEventCount,
        int selectedPartitionCount,
        int discoveredVehicleCount,
        List<UnifiedDiscoveredVehicleRef> discoveredVehicles,
        Map<String, RuntimeProcessingModuleResult> moduleResults,
        Map<String, RuntimeEventProcessingPartitionResultDto> partitionResults,
        List<String> notes,
        List<String> warnings
) {
    public RuntimeProcessingExecutionResultDto {
        executedModules = executedModules == null ? List.of() : List.copyOf(executedModules);
        discoveredVehicles = discoveredVehicles == null ? List.of() : List.copyOf(discoveredVehicles);
        moduleResults = moduleResults == null ? Map.of() : Collections.unmodifiableMap(new LinkedHashMap<>(moduleResults));
        partitionResults = partitionResults == null ? Map.of() : Collections.unmodifiableMap(new LinkedHashMap<>(partitionResults));
        notes = notes == null ? List.of() : List.copyOf(notes);
        warnings = warnings == null ? List.of() : List.copyOf(warnings);
    }

    public RuntimeProcessingExecutionResultDto(
            String processingPlanKey,
            List<String> executedModules,
            RuntimeEventPartitioningStrategy partitioningStrategy,
            UnifiedRuntimeProcessingRequest request,
            int inputEventCount,
            int selectedPartitionCount,
            int discoveredVehicleCount,
            List<UnifiedDiscoveredVehicleRef> discoveredVehicles,
            Map<String, RuntimeEventProcessingPartitionResultDto> partitionResults,
            List<String> notes,
            List<String> warnings
    ) {
        this(processingPlanKey, executedModules, partitioningStrategy, request, inputEventCount,
                selectedPartitionCount, discoveredVehicleCount, discoveredVehicles, Map.of(), partitionResults,
                notes, warnings);
    }
}
