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

import at.procon.eventhub.processing.eventprocessing.dto.RuntimeEventProcessingApiRequest;
import java.util.Set;

public record RuntimeMixedSourceEvidenceValidationApiRequest(
        RuntimeEventProcessingApiRequest processingRequest,
        Set<String> expectedPartitionKeys,
        Integer minimumAttachedVehicleEvidenceEvents,
        Integer minimumNormalizedSupportEvidenceEvents,
        Boolean failWhenPartitionDebugMissing
) {
    public RuntimeMixedSourceEvidenceValidationApiRequest {
        if (processingRequest == null) {
            throw new IllegalArgumentException("processingRequest must not be null.");
        }
        expectedPartitionKeys = expectedPartitionKeys == null ? Set.of() : Set.copyOf(expectedPartitionKeys);
        if (minimumAttachedVehicleEvidenceEvents != null && minimumAttachedVehicleEvidenceEvents < 0) {
            throw new IllegalArgumentException("minimumAttachedVehicleEvidenceEvents must not be negative.");
        }
        if (minimumNormalizedSupportEvidenceEvents != null && minimumNormalizedSupportEvidenceEvents < 0) {
            throw new IllegalArgumentException("minimumNormalizedSupportEvidenceEvents must not be negative.");
        }
    }

    public int minimumAttachedVehicleEvidenceEventsOrDefault() {
        return minimumAttachedVehicleEvidenceEvents == null ? 0 : Math.max(0, minimumAttachedVehicleEvidenceEvents);
    }

    public int minimumNormalizedSupportEvidenceEventsOrDefault() {
        return minimumNormalizedSupportEvidenceEvents == null ? 0 : Math.max(0, minimumNormalizedSupportEvidenceEvents);
    }

    public boolean failWhenPartitionDebugMissingOrDefault() {
        return failWhenPartitionDebugMissing == null || failWhenPartitionDebugMissing;
    }
}
