<?php

namespace App\Modules\HR\Attendance\Policies;

use App\Models\User;
use App\Modules\HR\Attendance\Models\AttendanceRecord;

class AttendanceRecordPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->can('attendance.view');
    }

    public function view(User $user, AttendanceRecord $record): bool
    {
        return $user->can('attendance.view', $record);
    }

    public function create(User $user): bool
    {
        return $user->can('attendance.create');
    }

    public function import(User $user): bool
    {
        return $user->can('attendance.import');
    }

    public function manage(User $user): bool
    {
        return $user->can('attendance.manage');
    }

    public function registerCheckout(User $user): bool
    {
        return $user->can('attendance.checkout.register') || $user->can('attendance.manage');
    }

    public function updateCheckout(User $user, AttendanceRecord $record): bool
    {
        return ($user->can('attendance.checkout.update') || $user->can('attendance.manage'))
            && (int) $user->tenant_id === (int) $record->tenant_id;
    }
}
