<?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('order_item_features', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('order_item_id');
            $table->uuid('feature_option_id');
            $table->decimal('price_at_time', 10, 2);
            $table->text('specifications')->nullable();
            $table->timestamps();

            $table->foreign('order_item_id')->references('id')->on('order_items')->onDelete('cascade');
            $table->foreign('feature_option_id')->references('id')->on('feature_options')->onDelete('cascade');
            $table->unique(['order_item_id', 'feature_option_id'], 'oi_fo_unique');
            $table->index(['order_item_id'], 'oi_fo_idx');
        });
    }

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