<?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_features', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('service_item_id');
            $table->uuid('feature_type_id');
            $table->boolean('is_required')->default(false);
            $table->integer('sort_order')->default(0);
            $table->timestamps();

            $table->foreign('service_item_id')->references('id')->on('service_items')->onDelete('cascade');
            $table->foreign('feature_type_id')->references('id')->on('feature_types')->onDelete('cascade');
            $table->unique(['service_item_id', 'feature_type_id'], 'si_ft_unique');
            $table->index(['service_item_id', 'sort_order'], 'si_ft_idx');
        });
    }

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