<?php

namespace Database\Factories;

use App\Domain\Applicants\Enums\ApplicantStatus;
use App\Domain\Organization\Models\Company;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class ApplicantFactory extends Factory
{
    public function definition(): array
    {
        return [
            'reference_no' => 'AT-TST-2026-'.Str::padLeft((string) $this->faker->unique()->numberBetween(1, 999999), 6, '0'),
            'company_id' => Company::factory(),
            'full_name' => $this->faker->name(),
            'gender' => $this->faker->randomElement(['male', 'female']),
            'date_of_birth' => $this->faker->dateTimeBetween('-45 years', '-22 years')->format('Y-m-d'),
            'mobile' => $this->faker->unique()->numerify('018########'),
            'email' => $this->faker->unique()->safeEmail(),
            'national_id' => $this->faker->unique()->numerify('##########'),
            'passport_number' => $this->faker->unique()->bothify('A#######'),
            'passport_expiry_date' => now()->addYears(5)->toDateString(),
            'source' => 'agent',
            'status' => ApplicantStatus::Lead->value,
        ];
    }

    public function status(ApplicantStatus $status): static
    {
        return $this->state(fn () => ['status' => $status->value]);
    }

    public function verified(): static
    {
        return $this->state(fn () => [
            'status' => ApplicantStatus::Registered->value,
            'verified_at' => now(),
        ]);
    }

    /** A passport that is present but no longer valid. */
    public function expiredPassport(): static
    {
        return $this->state(fn () => ['passport_expiry_date' => now()->subMonth()->toDateString()]);
    }
}
