<?php
namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use App\Models\Artwork;
use App\Models\ArtworkAward;
use App\Models\ArtworkComment;
use App\Models\Post;
use App\Models\PostComment;
use App\Policies\ArtworkPolicy;
use App\Policies\ArtworkAwardPolicy;
use App\Policies\ArtworkCommentPolicy;
use App\Policies\PostPolicy;
use App\Policies\PostCommentPolicy;

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        Artwork::class        => ArtworkPolicy::class,
        ArtworkAward::class   => ArtworkAwardPolicy::class,
        ArtworkComment::class => ArtworkCommentPolicy::class,
        Post::class           => PostPolicy::class,
        PostComment::class    => PostCommentPolicy::class,
    ];

    /**
     * Register any authentication / authorization services.
     */
    public function boot(): void
    {
        $this->registerPolicies();

        Gate::define('moderate-forum', static function ($user): bool {
            return method_exists($user, 'isAdmin') && ($user->isAdmin() || $user->isModerator());
        });
    }
}
