<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use App\Models\User;

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        //
    ];

    public function boot(): void
    {
        // Super Admin tiene acceso total a todo
        Gate::before(function (User $user, string $ability) {
            if ($user->isSuperAdmin()) {
                return true;
            }
        });

        // Permisos específicos
        Gate::define('view-session-history', function (User $user) {
            return $user->hasPermission('view-session-history');
        });

        Gate::define('manage-partners', function (User $user) {
            return $user->hasPermission('manage-partners');
        });

        Gate::define('view-all-users', function (User $user) {
            return $user->hasPermission('view-all-users');
        });

        Gate::define('view-partner-users', function (User $user) {
            return $user->isPartnerAdmin() && $user->partner_id;
        });

        Gate::define('manage-users', function (User $user) {
            return $user->isSuperAdmin();
        });
    }
} 