<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\MasterInduk;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        // Bersihkan data lama
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
        User::truncate();
        MasterInduk::truncate();
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');

        $whitelist = [
            ['nomor_induk' => '1234567890', 'role' => 'siswa', 'nama_pemilik' => 'Silvi Rahmawati'],
            ['nomor_induk' => '9988776655', 'role' => 'siswa', 'nama_pemilik' => 'Siti Nurhaliza'],
            ['nomor_induk' => '5566778899', 'role' => 'siswa', 'nama_pemilik' => 'Andi Pratama'],
            ['nomor_induk' => '198506152010012', 'role' => 'guru', 'nama_pemilik' => 'Rina Marlina'],
        ];

        foreach ($whitelist as $w) {
            MasterInduk::create($w);
        }

        // ISI USER ASLI 

        // ID 1: Silvi (Siswa)
        User::create([
            'id' => 1,
            'name' => 'Silvi Rahmawati',
            'email' => 'silvi.rahmawati@smkn1perpus.sch.id',
            'password' => Hash::make('password'),
            'role' => 'siswa',
            'nisn' => '1234567890',
            'no_hp' => '08123456789',
            'kelas' => 'XII RPL',
            'golongan' => 'A'
        ]);

        // ID 2: Budi (Admin/Penjaga)
        User::create([
            'id' => 2,
            'name' => 'Budi Santoso',
            'email' => 'budi.santoso@smkn1perpus.sch.id',
            'password' => Hash::make('password'),
            'role' => 'penjaga perpus',
            'nip' => '197812312005011',
        ]);

        // ID 3: Siti (Siswa)
        User::create([
            'id' => 3,
            'name' => 'Siti Nurhaliza',
            'email' => 'siti.nurhaliza@smkn1perpus.sch.id',
            'password' => Hash::make('password'),
            'role' => 'siswa',
            'nisn' => '9988776655',
            'no_hp' => '081998877665',
            'kelas' => 'XII RPL',
            'golongan' => 'B'
        ]);

        // ID 4: Andi (Siswa)
        User::create([
            'id' => 4,
            'name' => 'Andi Pratama',
            'email' => 'andi.pratama@smkn1perpus.sch.id',
            'password' => Hash::make('password'),
            'role' => 'siswa',
            'nisn' => '5566778899',
            'no_hp' => '081556677889',
            'kelas' => 'XII RPL',
            'golongan' => 'C'
        ]);

        // ID 5: Rina (Guru)
        User::create([
            'id' => 5,
            'name' => 'Rina Marlina',
            'email' => 'rina.marlina@smkn1perpus.sch.id',
            'password' => Hash::make('password'),
            'role' => 'guru',
            'nip' => '198506152010012',
        ]);
    }
}
