<?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('purchase_return_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('purchase_return_id')->constrained('purchase_returns')->onDelete('cascade');
            $table->unsignedBigInteger('product_id')->comment('商品 ID');
            
            $table->decimal('quantity_returned', 10, 2)->comment('退貨數量');
            $table->decimal('unit_price', 12, 2)->comment('退貨單價');
            $table->decimal('total_amount', 12, 2)->comment('小計金額');
            
            $table->string('batch_number', 100)->nullable()->comment('指定退回之批號');
            
            $table->timestamps();
            
            $table->index('product_id');
        });
    }

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