<?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::table('inventario_prenda_distribuciones', function (Blueprint $table) {
            if (! Schema::hasColumn('inventario_prenda_distribuciones', 'proveedor_id')) {
                $table->unsignedBigInteger('proveedor_id')->nullable()->after('bodega_id');
                $table->foreign('proveedor_id')->references('id')->on('proveedors')->onDelete('set null');
            }
        });
    }

    public function down()
    {
        Schema::table('inventario_prenda_distribuciones', function (Blueprint $table) {
            if (Schema::hasColumn('inventario_prenda_distribuciones', 'proveedor_id')) {
                $table->dropForeign(['proveedor_id']);
                $table->dropColumn('proveedor_id');
            }
        });
    }
};