<?php

declare(strict_types=1);

namespace App\Policies;

use App\Models\Faq;
use App\Models\User;

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

    public function view(?User $user, Faq $faq): bool
    {
        if ($faq->status === Faq::STATUS_APPROVED) {
            return true;
        }

        return $user !== null && (
            $user->id === $faq->created_by
            || $user->hasRole('admin')
        );
    }

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

    public function update(User $user, Faq $faq): bool
    {
        return $user->id === $faq->created_by || $user->hasRole('admin');
    }

    public function delete(User $user, Faq $faq): bool
    {
        return $user->id === $faq->created_by || $user->hasRole('admin');
    }

    public function restore(User $user, Faq $faq): bool
    {
        return $user->hasRole('admin');
    }

    public function forceDelete(User $user, Faq $faq): bool
    {
        return $user->hasRole('admin');
    }
}
