package at.procon.eventhub.tachographfilesession.model;

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

public record PeriodizedDriverActivityInterval(
        String intervalId,
        OffsetDateTime from,
        OffsetDateTime to,
        long durationSeconds,
        String activityType,
        String slot,
        String cardStatus,
        String drivingStatus,
        String registrationKey,
        String vehicleKey,
        String sourceKind,
        List<String> sourceIntervalIds,
        boolean synthetic,
        boolean clippedToRequestedPeriod,
        String level,
        long operatingPeriodNo,
        OffsetDateTime operatingPeriodStartedAt,
        boolean newOperatingPeriod,
        Long gapSincePreviousActivitySeconds
) {
    public PeriodizedDriverActivityInterval withTime(OffsetDateTime newFrom, OffsetDateTime newTo, boolean clipped) {
        return new PeriodizedDriverActivityInterval(
                intervalId,
                newFrom,
                newTo,
                java.time.Duration.between(newFrom, newTo).getSeconds(),
                activityType,
                slot,
                cardStatus,
                drivingStatus,
                registrationKey,
                vehicleKey,
                sourceKind,
                sourceIntervalIds,
                synthetic,
                clipped,
                level,
                operatingPeriodNo,
                operatingPeriodStartedAt,
                newOperatingPeriod,
                gapSincePreviousActivitySeconds
        );
    }

    public PeriodizedDriverActivityInterval asMerged(
            String mergedIntervalId,
            OffsetDateTime newTo,
            List<String> mergedSourceIntervalIds
    ) {
        return new PeriodizedDriverActivityInterval(
                mergedIntervalId,
                from,
                newTo,
                java.time.Duration.between(from, newTo).getSeconds(),
                activityType,
                slot,
                cardStatus,
                drivingStatus,
                registrationKey,
                vehicleKey,
                sourceKind,
                mergedSourceIntervalIds,
                synthetic,
                clippedToRequestedPeriod,
                "MERGED_ACTIVITY",
                operatingPeriodNo,
                operatingPeriodStartedAt,
                newOperatingPeriod,
                gapSincePreviousActivitySeconds
        );
    }
}
