<?php

namespace Database\Factories;

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

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SystemSetting>
 */
class SystemSettingFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = SystemSetting::class;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'key' => fake()->unique()->word(),
            'value' => [
                'enabled' => fake()->boolean(),
                'value' => fake()->word(),
            ],
            'group' => fake()->randomElement(['general', 'embedding', 'chunking', 'system']),
            'description' => fake()->sentence(),
            'is_public' => fake()->boolean(),
        ];
    }

    /**
     * 指定配置为嵌入模型配置
     */
    public function embedding(): static
    {
        return $this->state(fn (array $attributes) => [
            'group' => 'embedding',
            'value' => [
                'model_name' => fake()->randomElement(['text-embedding-ada-002', 'text-embedding-3-small', 'text-embedding-3-large']),
                'api_key' => 'sk-' . fake()->uuid(),
                'endpoint_url' => fake()->url(),
                'dimensions' => fake()->randomElement([1536, 3072]),
            ],
        ]);
    }

    /**
     * 指定配置为分块参数配置
     */
    public function chunking(): static
    {
        return $this->state(fn (array $attributes) => [
            'group' => 'chunking',
            'value' => [
                'chunk_size' => fake()->numberBetween(500, 2000),
                'chunk_overlap' => fake()->numberBetween(50, 200),
                'separator' => fake()->randomElement(["\n\n", "\n", " "]),
            ],
        ]);
    }

    /**
     * 指定配置为系统全局配置
     */
    public function system(): static
    {
        return $this->state(fn (array $attributes) => [
            'group' => 'system',
            'value' => [
                'system_name' => fake()->company(),
                'timeout' => fake()->numberBetween(30, 300),
                'max_retries' => fake()->numberBetween(1, 5),
            ],
        ]);
    }

    /**
     * 指定配置为公开配置
     */
    public function public(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_public' => true,
        ]);
    }

    /**
     * 指定配置为私有配置
     */
    public function private(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_public' => false,
        ]);
    }
}
