<?php

namespace Database\Factories;

use App\Models\ApiLog;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends Factory<ApiLog> */
class ApiLogFactory extends Factory
{
    public function definition(): array
    {
        return [
            'service' => fake()->randomElement(['fuel_finder', 'fred', 'anthropic', 'postcodes_io']),
            'method' => fake()->randomElement(['GET', 'POST']),
            'url' => fake()->url(),
            'status_code' => fake()->randomElement([200, 200, 200, 401, 429, 500]),
            'duration_ms' => fake()->numberBetween(50, 2000),
            'error' => null,
            'created_at' => fake()->dateTimeBetween('-7 days'),
        ];
    }

    public function failed(): static
    {
        return $this->state([
            'status_code' => fake()->randomElement([400, 401, 403, 429, 500, 503]),
            'error' => fake()->sentence(),
        ]);
    }
}
