<?php

namespace App\Policies;

use App\Models\Entry;
use App\Models\EntryReview;
use App\Models\User;

class EntryReviewPolicy
{
    public function viewAny(\App\Auth\XenForoUser $user): bool
    {
        if( $user->_can( 'romhackplaza', 'view' ) )
            return true;

        return false;
    }

    public function create(\App\Auth\XenForoUser $user, ?EntryReview $review = null ): bool
    {
        return $user->_can( 'romhackplaza', 'canSubmitEntry' );
    }

    public function update(\App\Auth\XenForoUser $user, ?EntryReview $review = null ): bool
    {
        // Staff editors
        if( $user->_can('romhackplaza', 'canEditOthersEntries') )
            return true;

        // Author.
        if( $user->_can( 'romhackplaza', 'canEditMyEntries' ) && $review->user_id === $user->user_id )
            return true;

        return false;
    }
}
