<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('plan_config_options', function (Blueprint $table) {
            $table->id();
            $table->foreignId('group_id')->constrained('plan_config_groups')->cascadeOnDelete();
            $table->string('name');
            $table->text('description')->nullable();
            $table->string('type', 50);
            $table->string('provisioning_key', 100)->nullable();
            $table->boolean('required')->default(false);
            $table->boolean('is_active')->default(true);
            $table->integer('min_qty')->nullable();
            $table->integer('max_qty')->nullable();
            $table->integer('step')->nullable()->default(1);
            $table->string('unit_label', 50)->nullable();
            $table->decimal('hourly_price', 10, 4)->nullable();
            $table->decimal('monthly_price', 10, 2)->nullable();
            $table->decimal('quarterly_price', 10, 2)->nullable();
            $table->decimal('semi_annual_price', 10, 2)->nullable();
            $table->decimal('annual_price', 10, 2)->nullable();
            $table->integer('sort_order')->default(0);
            $table->timestamps();

            $table->index(['group_id', 'sort_order']);
            $table->index('is_active');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('plan_config_options');
    }
};
