<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

class GuruSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $guru = [
            [
                'username' => 'Lina',
                'password' => Hash::make('konseling25'),
                'nama_guru' => 'Lina Eryana, S.Pd, M.M.Pd',
                'jabatan' => 'Guru BK',
                'jenis_kelamin' => 'P',
                'nip' => '196827052007012000',
            ],
            [
                'username' => 'Yani',
                'password' => Hash::make('konseling25'),
                'nama_guru' => 'Yani Agustiani Pamungkas, S.Pd',
                'jabatan' => 'Guru BK',
                'jenis_kelamin' => 'P',
                'nip' => ' - ',
            ],
            [
                'username' => 'Desy',
                'password' => Hash::make('konseling25'),
                'nama_guru' => 'Desy Rosita Nuriswandi, S.Pd',
                'jabatan' => 'Guru BK',
                'jenis_kelamin' => 'P',
                'nip' => ' - ',
            ],
            [
                'username' => 'Dian',
                'password' => Hash::make('konseling25'),
                'nama_guru' => 'Dian Rusdiyanto Syarifudin, S.P',
                'jabatan' => 'Guru BK',
                'jenis_kelamin' => 'L',
                'nip' => ' - ',
            ],
            [
                'username' => 'Yuliastuti',
                'password' => Hash::make('konseling25'),
                'nama_guru' => 'Yuliastuti Dewi Yulianti, S.Si., M.MPd',
                'jabatan' => 'Guru BK',
                'jenis_kelamin' => 'P',
                'nip' => ' - ',
            ],
        ];

        foreach ($guru as $item) {
            $user = User::create([
                'name' => $item['nama_guru'],
                'username' => $item['username'],
                'password' => $item['password'],
            ]);

            DB::table('gurus')->insert([
                [
                    'nama_guru' => $item['nama_guru'],
                    'jenis_kelamin' => $item['jenis_kelamin'],
                    'jabatan' => $item['jabatan'],
                    'nip' => $item['nip'],
                    'id_user' => $user->id,
                ],
            ]);

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