<?php

namespace Database\Factories;

use App\Models\PhoneVerification;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;

/**
 * @extends Factory<PhoneVerification>
 */
class PhoneVerificationFactory extends Factory
{
    protected $model = PhoneVerification::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'phone' => '6'.fake()->unique()->numerify('#######'),
            'otp' => Hash::make('1234'),
            'expires_at' => now()->addMinutes(10),
            'verified' => false,
        ];
    }

    public function expired(): static
    {
        return $this->state(fn (array $attributes) => [
            'expires_at' => now()->subMinute(),
        ]);
    }

    public function withOtp(string $otp): static
    {
        return $this->state(fn (array $attributes) => [
            'otp' => Hash::make($otp),
        ]);
    }
}
