<?php

   namespace App\Providers;

   use App\Models\Comment;
   use App\Models\Post;
   use App\Models\User;
   use Illuminate\Database\Eloquent\Model;
   use Illuminate\Database\Eloquent\Relations\Relation;
   use Illuminate\Http\Resources\Json\JsonResource;
   use Illuminate\Support\Facades\Gate;
   use Illuminate\Support\Facades\Schema;
   use Illuminate\Support\Facades\Vite;
   use Illuminate\Support\ServiceProvider;

   class AppServiceProvider extends ServiceProvider
   {
      /**
       * Register any application services.
       */
      public function register(): void {
         //
      }

      /**
       * Bootstrap any application services.
       */
      public function boot(): void {
         Vite::prefetch(concurrency:3);
         Gate::before(function($user, $ability) {
            return $user->hasRole('super-admin') ? true : NULL;
         });
         JsonResource::withoutWrapping();
         Model::preventLazyLoading();
         Model::automaticallyEagerLoadRelationships();
         Model::unguard();
         Relation::enforceMorphMap([
            'post'    => Post::class,
            'comment' => Comment::class,
            'user'    => User::class,
         ]);
         Schema::defaultStringLength(191);
      }
   }
