<?php

namespace App\Modules\HR\Attendance\Services;

use App\Modules\HR\Attendance\Support\AttendanceRecordStatus;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

final class AttendanceLateStatusResolver
{
    public function resolve(
        CarbonInterface $checkIn,
        CarbonInterface $checkOut,
        CarbonImmutable $latenessThreshold,
        float $halfDayMaxHours,
    ): string {
        if ($checkIn->gt($latenessThreshold)) {
            return AttendanceRecordStatus::LATE;
        }
        $hours = $checkIn->diffInMinutes($checkOut) / 60;

        return $hours > 0 && $hours < $halfDayMaxHours
            ? AttendanceRecordStatus::HALF_DAY
            : AttendanceRecordStatus::PRESENT;
    }
}
