<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('order_details', function (Blueprint $table) {
            $table->id();

            // Order delete হলে তার সব details ডিলিট হবে (আগের মতই)
            $table->foreignId('order_id')
                ->constrained()
                ->onDelete('cascade');

            // Product delete হলে details-ও ডিলিট হবে (আগের মতই behaviour)
            $table->foreignId('product_id')
                ->constrained()
                ->onDelete('cascade');

            $table->integer('quantity');
            $table->string('size')->nullable();

            // product_code সবসময় নাও থাকতে পারে, তাই nullable করলাম
            $table->string('product_code')->nullable();

            // এখানে আমরা বর্তমানে line total রাখছি (unit_price * quantity)
            $table->decimal('price', 10, 2)
                ->comment('line total = unit price * quantity');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('order_details');
    }
};
