<?php

namespace Database\Factories;

use App\Models\OtpChallenge;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

/** @extends Factory<OtpChallenge> */
class OtpChallengeFactory extends Factory
{
    protected $model = OtpChallenge::class;

    public function definition(): array
    {
        $destination = fake()->safeEmail();

        return [
            'uuid' => (string) Str::uuid(),
            'user_id' => User::factory(),
            'purpose' => 'login',
            'channel' => 'email',
            'destination' => $destination,
            'destination_hash' => hash('sha256', Str::lower($destination)),
            'otp_hash' => Hash::make('123456'),
            'attempts' => 0,
            'max_attempts' => 5,
            'expires_at' => now()->addMinutes(5),
            'requested_ip' => fake()->ipv4(),
        ];
    }
}
