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

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

public record RuntimeEventProcessingProfileDescriptorDto(
        String profileKey,
        String displayName,
        String description,
        RuntimeEventPartitioningStrategy defaultPartitioningStrategy,
        List<RuntimeEventPartitioningStrategy> supportedPartitioningStrategies,
        Set<String> requiredParameters,
        Set<String> optionalParameters
) {
    public RuntimeEventProcessingProfileDescriptorDto {
        supportedPartitioningStrategies = supportedPartitioningStrategies == null
                ? List.of()
                : List.copyOf(supportedPartitioningStrategies);
        requiredParameters = requiredParameters == null ? Set.of() : Set.copyOf(requiredParameters);
        optionalParameters = optionalParameters == null ? Set.of() : Set.copyOf(optionalParameters);
    }

    public static RuntimeEventProcessingProfileDescriptorDto from(RuntimeEventProcessingProfile profile) {
        if (profile == null) {
            throw new IllegalArgumentException("profile must not be null");
        }
        return new RuntimeEventProcessingProfileDescriptorDto(
                profile.profileKey(),
                profile.displayName(),
                profile.description(),
                profile.defaultPartitioningStrategy(),
                profile.supportedPartitioningStrategies(),
                profile.requiredParameters(),
                profile.optionalParameters()
        );
    }
}
