<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class UserSeeder extends Seeder
{
    public function run()
    {
        $defaultPassword = password_hash('password123', PASSWORD_DEFAULT);

        $data = [
            [
                'nama' => 'Super Admin',
                'username' => 'admin',
                'email' => 'admin@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Admin',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Budi Mahasiswa',
                'username' => 'mahasiswa',
                'email' => 'mahasiswa@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Mahasiswa',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Staf Tata Usaha',
                'username' => 'tu',
                'email' => 'tu@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'TU',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Dr. Dosen Pembimbing',
                'username' => 'dosen',
                'email' => 'dosen@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Dosen',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Staf Keuangan',
                'username' => 'keuangan',
                'email' => 'keuangan@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Keuangan',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Admin Keuangan Utama',
                'username' => 'adminkeuangan',
                'email' => 'adminkeuangan@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Administrasi Keuangan',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Panitia PMB',
                'username' => 'adminpmb',
                'email' => 'pmb@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Administrator PMB',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Ketua Program Studi',
                'username' => 'adminprodi',
                'email' => 'kaprodi@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Administrator Prodi',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Dosen Muda',
                'username' => 'dosennonnidn',
                'email' => 'dosenmuda@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Dosen Belum-NIDN',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'nama' => 'Pimpinan Universitas',
                'username' => 'pimpinan',
                'email' => 'rektor@kampus.ac.id',
                'password_hash' => $defaultPassword,
                'hints' => 'password123',
                'role' => 'Pimpinan',
                'status' => 'active',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ]
        ];

        // Kosongkan tabel terlebih dahulu agar tidak duplikat jika dijalankan ulang
        $this->db->table('users')->truncate();

        // Insert semua data
        $this->db->table('users')->insertBatch($data);
    }
}
