<?php

namespace Database\Factories;

use App\Enums\CertificateStatus;
use App\Enums\UserRole;
use App\Models\Participant;
use App\Models\User;
use App\Services\IcNumberService;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Participant>
 */
class ParticipantFactory extends Factory
{
    protected $model = Participant::class;

    public function definition(): array
    {
        $icService = app(IcNumberService::class);
        $ic = $this->faker->numerify('############');
        $user = User::first();

        return [
            'full_name' => strtoupper($this->faker->name()),
            'ic_number' => $icService->encrypt($ic),
            'ic_number_hash' => $icService->hash($ic),
            'participant_number' => 'A'.$this->faker->unique()->numerify('###'),
            'category' => $this->faker->randomElement(['5KM', '10KM', '21KM']),
            'certificate_status' => CertificateStatus::NotDownloaded->value,
            'imported_by' => $user?->id,
            'is_active' => true,
        ];
    }

    public function downloaded(): static
    {
        return $this->state(fn () => [
            'certificate_status' => CertificateStatus::Downloaded->value,
            'first_downloaded_at' => now(),
            'last_downloaded_at' => now(),
            'download_count' => 1,
        ]);
    }
}
