<?php

namespace App\Domain\Recruitment\Policies;

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

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

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

    public function view(User $user, JobDemand $demand): bool
    {
        return $user->can('job_demand.view')
            && $this->scopes->allows($user, 'job_demand.view', $demand, 'owner_id');
    }

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

    public function update(User $user, JobDemand $demand): bool
    {
        return $user->can('job_demand.update')
            && $this->scopes->allows($user, 'job_demand.update', $demand, 'owner_id');
    }

    public function approve(User $user, JobDemand $demand): bool
    {
        return $user->can('job_demand.approve')
            && $this->scopes->allows($user, 'job_demand.approve', $demand, 'owner_id');
    }

    public function close(User $user, JobDemand $demand): bool
    {
        return $user->can('job_demand.close')
            && $this->scopes->allows($user, 'job_demand.close', $demand, 'owner_id');
    }
}
