<?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 KepalaSekolahSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $guru = [
            [
                'username' => 'Nandang',
                'password' => Hash::make('konseling25'),
                'nama_guru' => 'Nandang Jauharudin, S.TP., M.P',
                'jabatan' => 'Kepala Sekolah',
                'jenis_kelamin' => 'L',
                'nip' => '197401212006041000',
            ],
        ];

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