<?php

namespace App\Providers;

use App\Models\PortalUser;
use App\Models\User;
use App\Observers\PortalUserObserver;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

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

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        // Register observers
        PortalUser::observe(PortalUserObserver::class);

        // Super-admin bypasses all permission checks
        Gate::before(function (User $user, string $ability) {
            if ($user->hasRole('super-admin')) {
                return true;
            }
        });
    }
}
