<?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('orders')) {
            throw new RuntimeException('The orders table must exist before enabling customer advances.');
        }

        if (! Schema::hasColumn('orders', 'partially_paid_amount')) {
            Schema::table('orders', function (Blueprint $table) {
                $table->decimal('partially_paid_amount', 24, 3)->default(0);
            });
        }
    }

    public function down(): void
    {
        // Keep existing partial-payment state intact on live installations.
    }
};
