<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\PlanConfigOption;
use App\Models\PlanConfigValue;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<PlanConfigValue>
 */
class PlanConfigValueFactory extends Factory
{
    protected $model = PlanConfigValue::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'option_id' => PlanConfigOption::factory(),
            'label' => fake()->words(2, true),
            'value' => fake()->optional()->word(),
            'hourly_price' => 0,
            'monthly_price' => 0,
            'quarterly_price' => 0,
            'semi_annual_price' => 0,
            'annual_price' => 0,
            'is_default' => false,
            'sort_order' => fake()->numberBetween(0, 100),
        ];
    }

    public function asDefault(): static
    {
        return $this->state(fn () => [
            'is_default' => true,
        ]);
    }

    public function withPrice(float $monthly = 10.00, float $hourly = 0.015): static
    {
        return $this->state(fn () => [
            'hourly_price' => $hourly,
            'monthly_price' => $monthly,
            'quarterly_price' => round($monthly * 3 * 0.95, 2),
            'semi_annual_price' => round($monthly * 6 * 0.90, 2),
            'annual_price' => round($monthly * 12 * 0.85, 2),
        ]);
    }
}
