<?php

namespace Database\Seeders;

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

class UserSeeder extends Seeder
{
    public function run()
    {
        $users = [
            [
                'name' => 'PAULUS S. K. LIMU',
                'email' => 'bupati@sumbatengah.go.id',
                'position' => 'BUPATI',
                'role' => 'Pembina',
                'village' => null,
            ],
            [
                'name' => 'WAKIL BUPATI',
                'email' => 'wakilbupati@sumbatengah.go.id',
                'position' => 'WAKIL BUPATI',
                'role' => 'Pengarah',
                'village' => null,
            ],
            [
                'name' => 'SEKRETARIS DAERAH',
                'email' => 'sekda@sumbatengah.go.id',
                'position' => 'SEKRETARIS DAERAH',
                'role' => 'Orang Tua Asuh',
                'village' => 'MATA REDI',
            ],
            [
                'name' => 'KEPALA DINAS KESEHATAN',
                'email' => 'kadis_kesehatan@sumbatengah.go.id',
                'position' => 'KEPALA DINAS KESEHATAN',
                'role' => 'Orang Tua Asuh',
                'village' => 'OLE ATE',
            ],
            [
                'name' => 'KEPALA BAGIAN UMUM',
                'email' => 'kabag_umum@sumbatengah.go.id',
                'position' => 'KEPALA BAGIAN UMUM',
                'role' => 'Orang Tua Asuh',
                'village' => 'ANAJIAKA',
            ],
            [
                'name' => 'KEPALA BIDANG IRIGASI',
                'email' => 'kabid_irigasi@sumbatengah.go.id',
                'position' => 'KEPALA BIDANG IRIGASI PADA DINAS PUPR',
                'role' => 'Orang Tua Asuh',
                'village' => 'BOLU BOKAT UTARA',
            ],
            [
                'name' => 'KEPALA BIDANG PSP',
                'email' => 'kabid_psp@sumbatengah.go.id',
                'position' => 'KEPALA BIDANG PSP DAN PENYULUHAN PADA DINAS PERTANIAN',
                'role' => 'Orang Tua Asuh',
                'village' => 'MANURARA',
            ],
            [
                'name' => 'KEPALA BAGIAN ORGANISASI',
                'email' => 'kabag_organisasi@sumbatengah.go.id',
                'position' => 'KEPALA BAGIAN ORGANISASI',
                'role' => 'Orang Tua Asuh',
                'village' => 'MATAWAI KAJAWI',
            ],
            [
                'name' => 'KEPALA BADAN KEUANGAN',
                'email' => 'kaban_keu@sumbatengah.go.id',
                'position' => 'KEPALA BADAN KEUANGAN',
                'role' => 'Orang Tua Asuh',
                'village' => 'ANAKALANG',
            ],
            [
                'name' => 'STAF AHLI BIDANG PEREKONOMIAN',
                'email' => 'stafahli_ekonomi@sumbatengah.go.id',
                'position' => 'STAF AHLI BIDANG PEREKONOMIAN KEUANGAN DAN PEMBANGUNAN',
                'role' => 'Orang Tua Asuh',
                'village' => 'UMBU MAMIJUK',
            ],
            [
                'name' => 'SEKRETARIS DINAS KESEHATAN',
                'email' => 'sek_dinkes@sumbatengah.go.id',
                'position' => 'SEKRETARIS DINAS KESEHATAN',
                'role' => 'Orang Tua Asuh',
                'village' => 'NGADU BOLU',
            ],
            [
                'name' => 'KEPALA BIDANG TANAMAN PANGAN',
                'email' => 'kabid_pangan@sumbatengah.go.id',
                'position' => 'KEPALA BIDANG TANAMAN PANGAN PADA DINAS PERTANIAN',
                'role' => 'Orang Tua Asuh',
                'village' => 'NGADU OLU',
            ],
            [
                'name' => 'KEPALA DINAS PETERNAKAN',
                'email' => 'kadis_peternakan@sumbatengah.go.id',
                'position' => 'KEPALA DINAS PETERNAKAN DAN KESEHATAN HEWAN',
                'role' => 'Orang Tua Asuh',
                'village' => 'SAMBALI LOKU',
            ],
            [
                'name' => 'KEPALA BIDANG SD',
                'email' => 'kabid_sd@sumbatengah.go.id',
                'position' => 'KEPALA BIDANG SD PADA DINAS PPO',
                'role' => 'Orang Tua Asuh',
                'village' => 'SUSU WENDEWA',
            ],
            [
                'name' => 'IRBAN II',
                'email' => 'irban2@sumbatengah.go.id',
                'position' => 'IRBAN II PADA INSPEKTORAT',
                'role' => 'Orang Tua Asuh',
                'village' => 'TANA MODU',
            ],
            [
                'name' => 'KEPALA BIDANG LITBANG',
                'email' => 'kabid_litbang@sumbatengah.go.id',
                'position' => 'KEPALA BIDANG LITBANG PADA BAPPERIDA',
                'role' => 'Orang Tua Asuh',
                'village' => 'UMBU KAWOLU',
            ],
            [
                'name' => 'SEKRETARIS DINAS PUPR',
                'email' => 'sek_pupr@sumbatengah.go.id',
                'position' => 'SEKRETARIS DINAS PU PR',
                'role' => 'Orang Tua Asuh',
                'village' => 'UMBU LANGANG',
            ],
            [
                'name' => 'KEPALA BAGIAN HUKUM',
                'email' => 'kabag_huk@sumbatengah.go.id',
                'position' => 'KEPALA BAGIAN HUKUM',
                'role' => 'Orang Tua Asuh',
                'village' => 'WAIMANU',
            ],
            [
                'name' => 'CAMAT',
                'email' => 'camat@sumbatengah.go.id',
                'position' => 'CAMAT',
                'role' => 'Koordinator Kecamatan',
                'village' => null,
            ],
            [
                'name' => 'KEPALA DESA',
                'email' => 'kades@sumbatengah.go.id',
                'position' => 'KEPALA DESA',
                'role' => 'Koordinator Desa',
                'village' => null,
            ],
        ];

        foreach ($users as $userData) {
            $user = User::create([
                'name' => $userData['name'],
                'email' => str_replace('@sumbatengah.go.id', '@sumbatengahkab.go.id', $userData['email']),
                'recovery_email' => 'recovery_' . str_replace('@sumbatengah.go.id', '@gmail.com', $userData['email']),
                'phone_number' => '0812' . rand(10000000, 99999999),
                'password' => Hash::make('password123'),
                'position' => $userData['position'],
                'village' => $userData['village'],
            ]);

            $user->assignRole($userData['role']);
        }

        // Add Super Admin
        $admin = User::create([
            'name' => 'Super Admin',
            'email' => 'admin@pom500.com',
            'password' => Hash::make('password'),
            'position' => 'Administrator',
            'village' => null,
        ]);
        $admin->assignRole('Admin');
    }
}
