<?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
    {
        if (! Schema::hasTable('couriers')) {
            return;
        }

        Schema::table('couriers', function (Blueprint $table) {
            if (! Schema::hasColumn('couriers', 'opening_balance_date')) {
                $table->date('opening_balance_date')->nullable()->after('opening_balance');
            }

            if (! Schema::hasColumn('couriers', 'opening_balance_reference')) {
                $table->string('opening_balance_reference')->nullable()->after('opening_balance_date');
            }

            if (! Schema::hasColumn('couriers', 'opening_balance_note')) {
                $table->text('opening_balance_note')->nullable()->after('opening_balance_reference');
            }

            if (! Schema::hasColumn('couriers', 'opening_balance_synced_at')) {
                $table->timestamp('opening_balance_synced_at')->nullable()->after('opening_balance_note');
            }
        });
    }

    public function down(): void
    {
        // Intentionally left empty to avoid accidental removal of live accounting metadata.
    }
};
