<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use App\Models\User;
use Illuminate\Support\ServiceProvider;


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

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        // Lista de todas as ações que são exclusivas de Admin
        $adminActions = [
            'createUser',
            'editUser',
            'deleteUser',
            'addClient', // Exemplo
            'deleteClient', // Exemplo
            'editClient',
        ];

        foreach ($adminActions as $action) {
            Gate::define($action, function (User $user) {
                // A lógica fica centralizada aqui. Se mudar, muda pra todos.
                return isset($user->permissions) && in_array('admin', $user->permissions);
            });
        }
    }
}
