<?php

namespace App\Domain\Recruitment\Policies;

use App\Domain\Identity\Models\User;
use App\Domain\Identity\Services\ScopeGuard;
use App\Domain\Recruitment\Models\Employer;

class EmployerPolicy
{
    public function __construct(private readonly ScopeGuard $scopes) {}

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

    public function view(User $user, Employer $employer): bool
    {
        return $user->can('employer.view')
            && $this->scopes->allows($user, 'employer.view', $employer, 'account_manager_id');
    }

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

    public function update(User $user, Employer $employer): bool
    {
        return $user->can('employer.update')
            && $this->scopes->allows($user, 'employer.update', $employer, 'account_manager_id');
    }

    public function approve(User $user, Employer $employer): bool
    {
        return $user->can('employer.approve')
            && $this->scopes->allows($user, 'employer.approve', $employer, 'account_manager_id');
    }
}
