package at.procon.eventhub.esperpoc.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.OffsetDateTime;
import java.util.UUID;

public record EsperOperatingPeriodRequest(
        @NotBlank String tenantKey,
        @NotNull UUID driverId,
        @NotNull OffsetDateTime occurredFrom,
        @NotNull OffsetDateTime occurredTo,
        Integer guardHours,
        Integer operatingSplitIdleHours,
        Integer significantDrivingMinutes,
        Integer mergeGapSeconds,
        Integer gapDetectionToleranceSeconds,
        EsperSourceSelectionMode sourceSelectionMode,
        EsperUnknownTreatmentMode unknownTreatmentMode,
        EsperOperatingPeriodEngineMode engineMode
) {
    public EsperOperatingPeriodRequest {
        if (occurredFrom != null && occurredTo != null && !occurredFrom.isBefore(occurredTo)) {
            throw new IllegalArgumentException("occurredFrom must be before occurredTo");
        }
        guardHours = guardHours == null ? 24 : Math.max(0, guardHours);
        operatingSplitIdleHours = operatingSplitIdleHours == null ? null : Math.max(1, operatingSplitIdleHours);
        significantDrivingMinutes = significantDrivingMinutes == null ? null : Math.max(1, significantDrivingMinutes);
        mergeGapSeconds = mergeGapSeconds == null ? null : Math.max(0, mergeGapSeconds);
        gapDetectionToleranceSeconds = gapDetectionToleranceSeconds == null ? null : Math.max(0, gapDetectionToleranceSeconds);
    }
}
