<?php

namespace App\Policies;

use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Spatie\Permission\Models\Role;

class RolesPolicy
{
    use HandlesAuthorization;

    /**
     * Create a new policy instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    public function create(User $user){
        return $user->hasAnyPermission(['control roles and permissions']);
    }
    public function update(User $user, Role $role){
        return $user->hasAnyPermission(['control roles and permissions']);
    }
    public function view(User $user){
        return $user->hasAnyPermission(['control roles and permissions']);
    }
    public function delete(User $user,Role $role){
        if($role->name =='super-admin' && count(User::role('super-admin')->get())<1){
            return false;
        }
        return $user->hasAnyPermission(['control roles and permissions']);
    }
    public function viewAny(User $user){
        return $user->hasAnyPermission(['control roles and permissions']);
    }
}
