<?php

namespace App\Policies;

use App\Models\RequirementQuestion;
use App\Models\User;

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

    public function view(User $user, RequirementQuestion $requirementQuestion): bool
    {
        return true;
    }

    public function create(User $user): bool
    {
        return $user->isAdmin();
    }

    public function update(User $user, RequirementQuestion $requirementQuestion): bool
    {
        return $user->isAdmin();
    }

    public function delete(User $user, RequirementQuestion $requirementQuestion): bool
    {
        return $user->isAdmin();
    }

    public function deleteAny(User $user): bool
    {
        return $user->isAdmin();
    }

    public function answer(User $user, RequirementQuestion $requirementQuestion): bool
    {
        if ($requirementQuestion->status !== 'open') {
            return false;
        }

        return $user->is_active
            && ($user->isAdmin() || $user->isCollaborator());
    }
}
