<?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::table('warehouses', function (Blueprint $table) {
            // Add new columns for WMS if they don't exist
            if (!Schema::hasColumn('warehouses', 'site_id')) {
                $table->unsignedBigInteger('site_id')->nullable();
            }
            if (!Schema::hasColumn('warehouses', 'is_active')) {
                $table->boolean('is_active')->default(true);
            }

            // Add indexes if they don't exist
            if (!Schema::hasIndex('warehouses', 'warehouses_code_is_active_index')) {
                $table->index(['code', 'is_active']);
            }
        });
    }

    /**
     * Reverse the migrations.
     */
        public function down(): void
    {
        Schema::table('warehouses', function (Blueprint $table) {
            // Remove WMS columns and indexes
            if (Schema::hasIndex('warehouses', 'warehouses_code_is_active_index')) {
                $table->dropIndex(['code', 'is_active']);
            }
            if (Schema::hasColumn('warehouses', 'is_active')) {
                $table->dropColumn('is_active');
            }
            if (Schema::hasColumn('warehouses', 'site_id')) {
                $table->dropColumn('site_id');
            }
        });
    }
};
