<?php

declare(strict_types=1);

namespace Database\Factories;

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

/**
 * @extends Factory<PlanConfigOption>
 */
class PlanConfigOptionFactory extends Factory
{
    protected $model = PlanConfigOption::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'group_id' => PlanConfigGroup::factory(),
            'name' => fake()->words(2, true),
            'description' => fake()->sentence(),
            'type' => 'dropdown',
            'provisioning_key' => fake()->optional()->word(),
            'required' => false,
            'is_active' => true,
            'min_qty' => null,
            'max_qty' => null,
            'step' => 1,
            'unit_label' => null,
            'hourly_price' => null,
            'monthly_price' => null,
            'quarterly_price' => null,
            'semi_annual_price' => null,
            'annual_price' => null,
            'sort_order' => fake()->numberBetween(0, 100),
        ];
    }

    public function slider(float $monthlyPerUnit = 5.00, float $hourlyPerUnit = 0.0075): static
    {
        return $this->state(fn () => [
            'type' => 'slider',
            'min_qty' => 1,
            'max_qty' => 64,
            'step' => 1,
            'unit_label' => 'GB',
            'hourly_price' => $hourlyPerUnit,
            'monthly_price' => $monthlyPerUnit,
            'quarterly_price' => round($monthlyPerUnit * 3 * 0.95, 2),
            'semi_annual_price' => round($monthlyPerUnit * 6 * 0.90, 2),
            'annual_price' => round($monthlyPerUnit * 12 * 0.85, 2),
        ]);
    }

    public function quantity(): static
    {
        return $this->state(fn () => [
            'type' => 'quantity',
            'min_qty' => 0,
            'max_qty' => 100,
            'step' => 1,
        ]);
    }

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

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