<?php

namespace App\Policies;

use App\Constants\Permissions;
use App\Models\Attendance;
use App\Models\User;

class AttendancePolicy
{
    public function viewAny(User $user): bool
    {
        return $user->hasRole('admin') || $user->hasPermissionTo(Permissions::ATTENDANCE_VIEW);
    }

    public function view(User $user, Attendance $attendance): bool
    {
        return $user->hasRole('admin')
            || ($user->id === $attendance->user_id)
            || $user->hasPermissionTo(Permissions::ATTENDANCE_VIEW);
    }

    public function update(User $user, Attendance $attendance): bool
    {
        return $user->hasRole('admin') || $user->hasPermissionTo(Permissions::ATTENDANCE_MANAGE);
    }
}
