<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class AdminUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $users = [
            [
                'Web Team','web@tuf.edu.pk','web-team','nTIjD5EAKM8UorTK'
            ],
            [
                'Ghulam Farid','ghulam.farid@tuf.edu.pk','ghulam-farid','farid@999000'
            ],
        ];
        foreach ($users as $u) {
            $user = User::create([
                'name' => $u[0],
                'email' => $u[1],
                'slug' => $u[2],
                'role_status' => 1,
                'status' => 1,
                'email_verified_at' => now(),
                'password' => bcrypt($u[3])
            ]);
            $role = Role::updateOrCreate(
                ['name' => 'Developer'],
                ['name' => 'Developer']
            );
            $permissions = Permission::pluck('id', 'id')->all();
            $role->syncPermissions($permissions);
            $user->assignRole([$role->id]);
        }
    }
}
