package at.procon.eventhub.tachographfilesession.model;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.UUID;

public record ResolvedVehicleUsageInterval(
        UUID sessionId,
        String driverKey,
        String intervalId,
        OffsetDateTime from,
        OffsetDateTime to,
        long durationSeconds,
        Long odometerBeginKm,
        Long odometerEndKm,
        String registrationKey,
        String vehicleKey,
        String sourceKind,
        List<String> sourceIntervalIds
) {
    public static ResolvedVehicleUsageInterval resolved(
            UUID sessionId,
            String driverKey,
            String intervalId,
            OffsetDateTime from,
            OffsetDateTime to,
            Long odometerBeginKm,
            Long odometerEndKm,
            String registrationKey,
            String vehicleKey,
            String sourceKind,
            List<String> sourceIntervalIds
    ) {
        return new ResolvedVehicleUsageInterval(
                sessionId,
                driverKey,
                intervalId,
                from,
                to,
                to == null ? 0L : Duration.between(from, to).getSeconds(),
                odometerBeginKm,
                odometerEndKm,
                registrationKey,
                vehicleKey,
                sourceKind,
                sourceIntervalIds == null ? List.of() : List.copyOf(sourceIntervalIds)
        );
    }
}
