<?php

namespace Database\Seeders;

use App\Enums\CertificateStatus;
use App\Models\Participant;
use App\Models\User;
use App\Services\IcNumberService;
use Illuminate\Database\Seeder;

class ParticipantSeeder extends Seeder
{
    public function run(): void
    {
        $icService = app(IcNumberService::class);
        $admin = User::first();

        $participants = [
            ['full_name' => 'AHMAD BIN ABDULLAH', 'ic' => '900101101234', 'no' => 'A001', 'cat' => '5KM'],
            ['full_name' => 'NURUL AIN BINTI ALI', 'ic' => '920202025678', 'no' => 'A002', 'cat' => '10KM'],
            ['full_name' => 'MUHAMMAD NUR HAKIM BIN ABDUL RAHMAN', 'ic' => '880303035789', 'no' => 'A003', 'cat' => '5KM'],
            ['full_name' => 'SITI AMINAH BINTI HASSAN', 'ic' => '950404046890', 'no' => 'A004', 'cat' => '21KM'],
            ['full_name' => 'RAJ KUMAR A/L SUBRAMANIAM', 'ic' => '870505057901', 'no' => 'A005', 'cat' => '10KM'],
        ];

        foreach ($participants as $p) {
            Participant::updateOrCreate(
                ['ic_number_hash' => $icService->hash($p['ic'])],
                [
                    'full_name' => $p['full_name'],
                    'ic_number' => $icService->encrypt($p['ic']),
                    'participant_number' => $p['no'],
                    'category' => $p['cat'],
                    'certificate_status' => CertificateStatus::NotDownloaded->value,
                    'imported_by' => $admin?->id,
                    'is_active' => true,
                ]
            );
        }
    }
}
