<?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('pos_order_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('order_id')->constrained('pos_orders')->onDelete('cascade');
            $table->foreignId('menu_item_id')->constrained('pos_menu_items')->onDelete('cascade');
            $table->string('item_name'); // Store name for historical reference
            $table->decimal('price', 10, 2);
            $table->integer('quantity')->default(1);
            $table->decimal('discount_percent', 5, 2)->default(0);
            $table->decimal('discount_amount', 10, 2)->default(0);
            $table->decimal('total', 10, 2); // (price * quantity) - discount
            $table->text('notes')->nullable(); // Special instructions
            $table->timestamps();
            
            $table->index('order_id');
            $table->index('menu_item_id');
        });
    }

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