package at.procon.eventhub.processing.dto;

import at.procon.eventhub.processing.model.UnifiedEventSourceFamily;
import at.procon.eventhub.processing.model.UnifiedRuntimeEventBackend;
import at.procon.eventhub.processing.model.UnifiedRuntimeProcessingRequest;
import at.procon.eventhub.processing.model.UnifiedTachographSourceKind;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Set;
import java.util.UUID;

public record UnifiedRuntimeProcessingApiRequest(
        UUID sessionId,
        List<UUID> sessionIds,
        UUID compositeSessionId,
        String tenantKey,
        Set<UnifiedEventSourceFamily> sourceFamilies,
        UnifiedRuntimeEventBackend eventBackend,
        Set<UnifiedTachographSourceKind> tachographSourceKinds,
        String driverKey,
        Set<String> driverKeys,
        Boolean includeAllDrivers,
        Set<String> vehicleKeys,
        Boolean includeAllVehicles,
        String driverSourceEntityId,
        String driverCardNation,
        String driverCardNumber,
        OffsetDateTime occurredFrom,
        OffsetDateTime occurredTo,
        Boolean expandVehicleEvents,
        Integer vehicleExpansionPaddingMinutes,
        Integer significantDrivingMinutes,
        Integer minimumRestPeriodMinutes
) {
    public UnifiedRuntimeProcessingRequest toRuntimeRequest() {
        return new UnifiedRuntimeProcessingRequest(
                sessionId,
                sessionIds,
                compositeSessionId,
                tenantKey,
                sourceFamilies,
                eventBackend,
                tachographSourceKinds,
                driverKey,
                driverKeys,
                includeAllDrivers != null && includeAllDrivers,
                vehicleKeys,
                includeAllVehicles != null && includeAllVehicles,
                driverSourceEntityId,
                driverCardNation,
                driverCardNumber,
                occurredFrom,
                occurredTo,
                expandVehicleEvents == null || expandVehicleEvents,
                vehicleExpansionPaddingMinutes == null ? 0 : Math.max(0, vehicleExpansionPaddingMinutes)
        );
    }
}
