<?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 WaliKelasSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $guru = [
            [
                'username' => 'Ahmad',
                'password' => Hash::make('konseling25'),
                'nip' => '198309192010011011',
                'nama_guru' => 'Ahmad Irsan S, S.Pd',
                'jabatan' => 'Wali Kelas XII TKJ 2',
                'jenis_kelamin' => 'L',
            ],
            [
                'username' => 'Gingin',
                'password' => Hash::make('konseling25'),
                'nip' => '-',
                'nama_guru' => 'Gingin Ginanjar S, S.Pd., M.MPd',
                'jabatan' => 'Wali Kelas XII TKJ 3',
                'jenis_kelamin' => 'L',
            ],
        ];

        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('WaliKelas');
        }
    }
}
