<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('tbl_orders', function (Blueprint $table) {
            if (! Schema::hasColumn('tbl_orders', 'remote_order_id')) {
                $table->unsignedInteger('remote_order_id')->nullable()->unique()->after('id_order');
            }
        });
    }

    public function down(): void
    {
        Schema::table('tbl_orders', function (Blueprint $table) {
            if (Schema::hasColumn('tbl_orders', 'remote_order_id')) {
                $table->dropUnique(['remote_order_id']);
                $table->dropColumn('remote_order_id');
            }
        });
    }
};
