<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Subject; // Pastikan Model Subject di-use
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        // 1. Buat SUPER ADMIN
        User::create([
            'name' => 'Super Administrator',
            'email' => 'admin@sekolah.id',
            'password' => Hash::make('password'), // Password: password
            'role' => 'super_admin',
            'subject_id' => null, // Super admin tidak punya mapel
        ]);

        // --- Opsional: Buat Data Dummy Lain ---

        // Pastikan ada Mapel dulu (misal ID 1 = Matematika)
        // Kita cek dulu, kalau tabel subjects kosong, kita buat satu
        $mapel = Subject::first();
        if(!$mapel) {
            $mapel = Subject::create(['name' => 'Matematika', 'code' => 'MTK']);
        }

        // 2. Buat ADMIN MAPEL (Matematika)
        User::create([
            'name' => 'Koordinator Matematika',
            'email' => 'kajur@sekolah.id',
            'password' => Hash::make('password'),
            'role' => 'admin_mapel',
            'subject_id' => $mapel->id,
        ]);

        // 3. Buat GURU BIASA (Matematika)
        User::create([
            'name' => 'Budi Guru MTK',
            'email' => 'guru@sekolah.id',
            'password' => Hash::make('password'),
            'role' => 'guru_mapel',
            'subject_id' => $mapel->id,
        ]);
    }
}