<?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\Models\Model' => 'App\Policies\ModelPolicy',
    ];

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

        /* define a superadmin user role */
        Gate::define('isSuperadmin', function($user){
            return $user->role == 'superadmin';
        });

        /* define a admin user role */
        Gate::define('isAdmin', function($user){
            return $user->role == 'admin';
        });

        /* define a superadmin or admin user role */
        Gate::define('isSuperadminOrAdmin', function($user){
            return $user->role == 'superadmin' || $user->role == 'admin';
        });

        /* define a user role */
        Gate::define('isUser', function($user){
            return $user->role == 'user';
        });

        /* define a admin or user role */
        Gate::define('isAdminOrUser', function($user){
            return $user->role == 'admin' || $user->role == 'user';
        });

    }
}
