<?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\AcademyChallenge;
use App\Models\AcademyChallengeSubmission;
use App\Models\AcademyLesson;
use App\Models\AcademyPromptPack;
use App\Models\AcademyPromptTemplate;
use App\Models\EnhanceJob;
use App\Models\Collection;
use App\Models\Group;
use App\Models\NovaCard;
use App\Models\Post;
use App\Models\PostComment;
use App\Models\World;
use App\Policies\ArtworkPolicy;
use App\Policies\ArtworkAwardPolicy;
use App\Policies\ArtworkCommentPolicy;
use App\Policies\AcademyChallengePolicy;
use App\Policies\AcademyChallengeSubmissionPolicy;
use App\Policies\AcademyLessonPolicy;
use App\Policies\AcademyPromptPackPolicy;
use App\Policies\AcademyPromptTemplatePolicy;
use App\Policies\EnhanceJobPolicy;
use App\Policies\CollectionPolicy;
use App\Policies\GroupPolicy;
use App\Policies\NovaCardPolicy;
use App\Policies\PostPolicy;
use App\Policies\PostCommentPolicy;
use App\Policies\WorldPolicy;

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        Artwork::class        => ArtworkPolicy::class,
        ArtworkAward::class   => ArtworkAwardPolicy::class,
        ArtworkComment::class => ArtworkCommentPolicy::class,
        AcademyChallenge::class => AcademyChallengePolicy::class,
        AcademyChallengeSubmission::class => AcademyChallengeSubmissionPolicy::class,
        AcademyLesson::class => AcademyLessonPolicy::class,
        AcademyPromptPack::class => AcademyPromptPackPolicy::class,
        AcademyPromptTemplate::class => AcademyPromptTemplatePolicy::class,
        EnhanceJob::class => EnhanceJobPolicy::class,
        Collection::class     => CollectionPolicy::class,
        Group::class          => GroupPolicy::class,
        NovaCard::class       => NovaCardPolicy::class,
        Post::class           => PostPolicy::class,
        PostComment::class    => PostCommentPolicy::class,
        World::class          => WorldPolicy::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());
        });
    }
}
