<?php

namespace App\Providers;

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

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot(){
        $this->registerPolicies();


        //pour capturer et valider l'autorisation de l'user authentifié
        Gate::before(function ($user,$ability){
            //Permissions non enregistrées en BD
            $exceptsAbilities = [
                "edit-account", "user-comment-ticket",
                "user-create-ticket", "update-role",
            ];

            /* Si la permission a verifié n'est pas parmis celle enregistrés en BD
            Afin de permettre de Bypasser le Gate de Spatie-Permission */
            if (!in_array($ability,$exceptsAbilities)){
                return $user->hasPermissionTo($ability,activeGuard());
            }
        });

//        // Implicitly grant "Admin" role all permissions
//        Gate::before(function ($user, $ability) {
//            return $user->hasRole('admin') ? true : null;
//        });
    }
}
