<?php

namespace Database\Factories;

use App\Models\LoginHistory;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends Factory<LoginHistory>
 */
class LoginHistoryFactory extends Factory
{
    protected $model = LoginHistory::class;

    public function definition(): array
    {
        $authenticatedAt = now()->subDays(fake()->numberBetween(0, 14))->subMinutes(fake()->numberBetween(1, 180));

        return [
            'user_id' => User::factory(),
            'session_id' => Str::random(40),
            'ip_address' => fake()->ipv4(),
            'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
            'device_name' => fake()->randomElement(['Windows / Chrome', 'Mac / Safari', 'Android / Chrome']),
            'authenticated_at' => $authenticatedAt,
            'last_seen_at' => (clone $authenticatedAt)->addMinutes(fake()->numberBetween(5, 180)),
        ];
    }
}
