<?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_items', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('order_id');
            $table->uuid('service_item_id');
            $table->uuid('vendor_service_id');
            $table->string('item_name');
            $table->decimal('unit_price', 10, 2);
            $table->decimal('quantity', 8, 2);
            $table->decimal('total_price', 10, 2);
            $table->text('design_file')->nullable();
            $table->text('specifications')->nullable();
            $table->json('custom_options')->nullable();
            $table->timestamps();

            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
            $table->foreign('service_item_id')->references('id')->on('service_items')->onDelete('cascade');
            $table->foreign('vendor_service_id')->references('id')->on('vendor_services')->onDelete('cascade');
            $table->index(['order_id', 'service_item_id']);
        });
    }

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