<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('ojales', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('proveedor_id')->nullable();
            $table->unsignedBigInteger('orden_produccion_id');
            $table->date('fecha_envio')->nullable();
            $table->integer('cantidad_enviada')->default(0);
            $table->date('fecha_recepcion')->nullable();
            $table->integer('cantidad_recibida')->nullable();
            $table->integer('perdidas')->default(0);
            $table->timestamps();

            $table->foreign('proveedor_id')->references('id')->on('proveedors')->onDelete('set null');
            $table->foreign('orden_produccion_id')->references('id')->on('orden_produccions')->onDelete('cascade');
        });
    }

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