<?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('movimiento_inventario_detalle', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('idMovimiento');
            $table->unsignedBigInteger('idProducto');
            $table->decimal('cantidad', 18, 4);
            $table->decimal('precioUnitario', 12, 4)->nullable();
            $table->timestamps();

            $table->foreign('idMovimiento', 'fk_mid_movimiento')
                  ->references('id')->on('movimiento_inventario')
                  ->onDelete('cascade');
            
            $table->foreign('idProducto', 'fk_mid_producto')
                  ->references('id')->on('products');
        });
    }

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