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

import at.procon.eventhub.processing.eventprocessing.partition.RuntimeEventPartitioningStrategy;
import java.util.List;
import java.util.Set;

public record RuntimeProcessingPlanDescriptorDto(
        String processingPlanKey,
        Set<String> aliases,
        String displayName,
        String description,
        RuntimeEventPartitioningStrategy defaultPartitioningStrategy,
        List<RuntimeEventPartitioningStrategy> supportedPartitioningStrategies,
        List<RuntimeProcessingModuleDescriptorDto> modules,
        Set<String> requiredParameters,
        Set<String> optionalParameters
) {
    public RuntimeProcessingPlanDescriptorDto {
        supportedPartitioningStrategies = supportedPartitioningStrategies == null
                ? List.of()
                : List.copyOf(supportedPartitioningStrategies);
        modules = modules == null ? List.of() : List.copyOf(modules);
        aliases = aliases == null ? Set.of() : Set.copyOf(aliases);
        requiredParameters = requiredParameters == null ? Set.of() : Set.copyOf(requiredParameters);
        optionalParameters = optionalParameters == null ? Set.of() : Set.copyOf(optionalParameters);
    }

    public static RuntimeProcessingPlanDescriptorDto from(RuntimeProcessingPlan plan) {
        if (plan == null) {
            throw new IllegalArgumentException("plan must not be null");
        }
        return new RuntimeProcessingPlanDescriptorDto(
                plan.processingPlanKey(),
                plan.aliases(),
                plan.displayName(),
                plan.description(),
                plan.defaultPartitioningStrategy(),
                plan.supportedPartitioningStrategies(),
                plan.modules(),
                plan.requiredParameters(),
                plan.optionalParameters()
        );
    }
}
