<?php

namespace App\Modules\HR\Employees\Policies;

use App\Models\User;
use App\Modules\HR\Employees\Models\Employee;

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

    public function view(User $user, Employee $employee): bool
    {
        if ((int) $user->tenant_id !== (int) $employee->tenant_id) {
            return false;
        }
        if ($user->employee_id !== null && (int) $user->employee_id === (int) $employee->id) {
            return true;
        }

        return $user->can('employees.view', $employee);
    }

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

    public function update(User $user, Employee $employee): bool
    {
        return $user->can('employees.update', $employee);
    }

    public function deactivate(User $user, Employee $employee): bool
    {
        return $user->can('employees.deactivate', $employee);
    }
}
