<?php
/*=========================================================================================
    App Name  : PPID PTUN Kupang
    File Name : UserSeeder
    --------------------------------------------------------------------------------------
    Author    : Fuad Auliya Rohman
    Email     : fuad.dev16@gmail.com
==========================================================================================*/

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Permission;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        /* Role User */
        Role::insert([
            [
                'name'         => 'superadmin',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'ketua',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'wakil ketua',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'plh ketua',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'plh waki ketua',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'panitera',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'panmud perkara',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'panmud hukum',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'plh panitera',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'plh panmud perkara',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'plh panmud hukum',
                'startup_page' => 'admin.dashboard',
                'guard_name'   => 'web',
            ],
            [
                'name'         => 'user',
                'startup_page' => 'user.dashboard',
                'guard_name'   => 'web',
            ],
        ]);

        $superadmin    = Permission::pluck('id', 'id')->all();
        $ketua          = ['1', '6', '7', '8', '9'];
        $panitera       = ['1', '10', '11', '12', '13'];
        $panmud_perkara = ['1', '14', '15', '26', '17'];
        $panmud_hukum   = ['1', '18', '19', '20', '21'];
        $user   = ['1', '22', '23', '24', '25'];

        $role = Role::findByName('superadmin');
        $user = User::create([
            'role_id'    => $role->id,
            'name'       => 'Superadmin',
            'username'   => 'superadmin',
            'password'   => Hash::make('password'),
            'is_active'  => "Y",
            'is_read'    => 1,
        ]);

        $role->syncPermissions($superadmin);
        $user->assignRole($role->id);

        $role = Role::findByName('ketua');
        $user = User::create([
            'role_id'    => $role->id,
            'name'       => 'I GEDE EKA PUTRA SUARTANA, S.H ,M.H.',
            'username'   => 'ketua',
            'password'   => Hash::make('ketua'),
            'is_active'  => "Y",
            'is_read'    => 1,
        ]);

        $role->syncPermissions($ketua);
        $user->assignRole(2);

        $role = Role::findByName('wakil ketua');
        $user = User::create([
            'role_id'    => $role->id,
            'name'       => 'ARDOYO WARDHANA, S.H., M.H.',
            'username'   => 'wakil_ketua',
            'password'   => Hash::make('wakil_ketua'),
            'is_active'  => "Y",
            'is_read'    => 1,
        ]);

        $role->syncPermissions($ketua);
        $user->assignRole(3);

        $role = Role::findByName('user');
        $user = User::create([
            'role_id'    => $role->id,
            'name'       => 'User',
            'username'   => 'user',
            'password'   => Hash::make('123456789'),
            'is_active'  => "Y",
            'is_read'    => 1,
        ]);

        $role->syncPermissions($user);
        $user->assignRole(12);

    }
}
