<?php

namespace App\Http\Controllers;

use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\Models\User;
use Illuminate\Support\Facades\Auth;

class UserPermissionController extends Controller
{
    public function createWitelRole()
    {
        $role = Role::create(['name' => 'witel']);
        
        $user = User::find(470);

        $user->assignRole('witel');

    }

    public function createAdminRole()
    {
        $role = Role::create(['name' => 'admin']);
        
        $user = User::find(469);

        $user->assignRole('admin');
    }

    public function createImenivaharimRole()
    {
        $role = Role::create(['name' => 'imenivaharim']);
        
        $users = User::where('username', 'like', '%imenivaharim%')
            ->get();

        foreach ($users as $user) {
            $user->assignRole('imenivaharim');
        }
    }

    public function createOstaniRole()
    {
        // $role = Role::create(['name' => 'edaratostani']);
        
        // $users = User::where('username', 'like', 'expert%')
        // ::where('username', 'like', '%.imenivaharim')
        //              ->orWhere('username', 'like', '%.negahdariabnie')
        //              ->orWhere('username', 'like', '%.negahdarirah')
        //              ->orWhere('username', 'like', '%.mashinalat')
        //              ->orWhere('username', 'like', '%.rahroostayi')
        // ->get();
        // return $users;
        // $i = 1;
        // foreach($users as $user)
        // $users = User::where('username', 'like', 'expert%')
        // ->orWhere('username', 'apirnoun')
        // ->orWhere('username', 'mrzamanian')
        // ->orWhere('username', 'msabbaghzadeh')
        // ->orWhere('username', 'mroudbari')
        // ->orWhere('username', 'hzakeri')
        // ->orWhere('username', 'akhanghaei')
        // ->orWhere('username', 'shkhavari')
        // ->orWhere('username', 'aashouri')
        // ->orWhere('username', 'ahasannia')
        // ->get();
        // $role = Role::create(['name' => 'setadi']);
        // $users = User::whereBetween('id', ['874','884'])->get();
        // $users = User::where('id', 885)->get();
        // foreach ($users as $user) {
        //     $user->assignRole('edaratostani');
        // }
        // return $users;
        return 'i love you';
    }
}