<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Enums\UserVerificationType;
use App\Enums\VerificationStatus;
use App\Models\User;
use App\Models\UserVerification;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<UserVerification>
 */
class UserVerificationFactory extends Factory
{
    protected $model = UserVerification::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'type' => UserVerificationType::Identity,
            'status' => VerificationStatus::Unverified,

            // Explicit nullables, so a created model matches a retrieved one.
            'provider' => null,
            'provider_reference' => null,
            'evidence_disk' => null,
            'evidence_path' => null,
            'metadata' => null,
            'submitted_at' => null,
            'verified_at' => null,
            'expires_at' => null,
            'failure_reason' => null,
            'reviewed_by' => null,
            'reviewed_at' => null,
        ];
    }

    public function identityVerified(): static
    {
        return $this->state(fn (): array => [
            'type' => UserVerificationType::Identity,
            'status' => VerificationStatus::Verified,
            'verified_at' => now(),
        ]);
    }

    public function paymentVerified(): static
    {
        return $this->state(fn (): array => [
            'type' => UserVerificationType::Payment,
            'status' => VerificationStatus::Verified,
            'verified_at' => now(),
        ]);
    }

    public function pending(): static
    {
        return $this->state(fn (): array => [
            'status' => VerificationStatus::Pending,
            'submitted_at' => now(),
        ]);
    }

    /** Verified but lapsed -- an expired check is not a current one. */
    public function expired(): static
    {
        return $this->state(fn (): array => [
            'status' => VerificationStatus::Verified,
            'verified_at' => now()->subYear(),
            'expires_at' => now()->subDay(),
        ]);
    }
}
