<?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', 'province_id')) {
                $table->unsignedInteger('province_id')->nullable()->after('postal_code');
            }

            if (! Schema::hasColumn('tbl_orders', 'canton_id')) {
                $table->unsignedInteger('canton_id')->nullable()->after('province_id');
            }

            if (! Schema::hasColumn('tbl_orders', 'district_id')) {
                $table->unsignedInteger('district_id')->nullable()->after('canton_id');
            }
        });
    }

    public function down(): void
    {
        // No hacemos drop para evitar pérdida de datos.
    }
};
