<?php

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('service_item_feature_options', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('service_item_id');
            $table->uuid('feature_option_id');
            $table->boolean('is_available')->default(true);
            $table->decimal('price_adjustment', 10, 2)->default(0);
            $table->enum('price_adjustment_type', ['fixed', 'percentage'])->default('fixed');
            $table->integer('sort_order')->default(0);
            $table->timestamps();

            $table->foreign('service_item_id')->references('id')->on('service_items')->onDelete('cascade');
            $table->foreign('feature_option_id')->references('id')->on('feature_options')->onDelete('cascade');
            $table->unique(['service_item_id', 'feature_option_id'], 'si_fo_unique');
            $table->index(['service_item_id', 'is_available', 'sort_order'], 'si_fo_idx');
        });
    }

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