<?php

namespace Database\Factories;

use App\Enums\AiUsageStatus;
use App\Enums\AiUsageType;
use App\Models\AiUsage;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<AiUsage>
 */
class AiUsageFactory extends Factory
{
    protected $model = AiUsage::class;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'type' => AiUsageType::MEAL_IMAGE_ANALYSIS,
            'status' => AiUsageStatus::SUCCESS,
            'input' => [
                'image' => [
                    'mime_type' => 'image/png',
                    'size' => 1024,
                ],
            ],
            'output' => [
                'title' => $this->faker->words(3, true),
            ],
            'provider' => null,
            'model' => null,
            'prompt_tokens' => null,
            'completion_tokens' => null,
            'total_tokens' => null,
            'error_message' => null,
            'related_type' => null,
            'related_id' => null,
        ];
    }

    public function failed(): static
    {
        return $this->state(fn (): array => [
            'status' => AiUsageStatus::FAILED,
            'output' => null,
            'error_message' => $this->faker->sentence(),
        ]);
    }
}
