<?php

namespace App\Policies;

use App\Models\ImportedJob;
use App\Models\User;

class ImportedJobPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->canViewMatchedJobs();
    }

    public function view(User $user, ImportedJob $importedJob): bool
    {
        return $user->canViewMatchedJobs()
            && $importedJob->status === ImportedJob::STATUS_ACTIVE
            && ($importedJob->expires_at === null || $importedJob->expires_at->isFuture());
    }

    public function save(User $user, ImportedJob $importedJob): bool
    {
        return $this->view($user, $importedJob);
    }

    public function apply(User $user, ImportedJob $importedJob): bool
    {
        return $user->canApplyToJobs()
            && $this->view($user, $importedJob);
    }
}
