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

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

public record RuntimeEventPartitioningApiRequest(
        RuntimeEventPartitioningStrategy strategy,
        Set<String> partitionKeys,
        Boolean includeAllPartitions,
        Set<String> driverKeys,
        Boolean includeAllDrivers,
        Set<String> vehicleKeys,
        Boolean includeAllVehicles,
        Boolean attachVehicleEvidence,
        Integer vehicleEvidencePaddingMinutes,
        Boolean includeDebug
) {
    public RuntimeEventPartitioningApiRequest {
        strategy = strategy == null ? RuntimeEventPartitioningStrategy.CUSTOM_PROFILE : strategy;
        partitionKeys = partitionKeys == null ? Set.of() : Set.copyOf(partitionKeys);
        driverKeys = driverKeys == null ? Set.of() : Set.copyOf(driverKeys);
        vehicleKeys = vehicleKeys == null ? Set.of() : Set.copyOf(vehicleKeys);
        if (vehicleEvidencePaddingMinutes != null && vehicleEvidencePaddingMinutes < 0) {
            throw new IllegalArgumentException("vehicleEvidencePaddingMinutes must not be negative");
        }
    }

    public boolean allPartitions() {
        return includeAllPartitions != null && includeAllPartitions;
    }

    public boolean allDrivers() {
        return includeAllDrivers != null && includeAllDrivers;
    }

    public boolean allVehicles() {
        return includeAllVehicles != null && includeAllVehicles;
    }

    public boolean attachVehicleEvidenceOrDefault() {
        return attachVehicleEvidence == null || attachVehicleEvidence;
    }

    public int vehicleEvidencePaddingMinutesOrDefault(int fallback) {
        return vehicleEvidencePaddingMinutes == null ? Math.max(0, fallback) : Math.max(0, vehicleEvidencePaddingMinutes);
    }

    public boolean includeDebugOrDefault() {
        return includeDebug != null && includeDebug;
    }
}
