<?php

declare(strict_types=1);

namespace App\Policies;

use App\Models\ProjectRequest;
use App\Models\User;

class ProjectRequestPolicy
{
    public function viewAny(User $user): bool
    {
        return true;
    }

    public function view(User $user, ProjectRequest $projectRequest): bool
    {
        if ($user->hasRole('admin')) {
            return true;
        }

        return $projectRequest->producer?->user_id === $user->id
            || $projectRequest->created_by === $user->id;
    }

    public function create(User $user): bool
    {
        return $user->hasRole('admin') || $user->producer()->exists();
    }

    public function updateStatus(User $user, ProjectRequest $projectRequest): bool
    {
        return $user->hasRole('admin');
    }

    public function message(User $user, ProjectRequest $projectRequest): bool
    {
        return $user->hasRole('admin');
    }
}
