<?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('opening_balances', function (Blueprint $table) {
            $table->foreignId('voucher_id')->nullable()->after('as_of_date')->constrained()->nullOnDelete();
            $table->enum('dr_cr', ['dr', 'cr'])->nullable()->after('voucher_id');
            $table->decimal('posted_amount', 18, 2)->default(0)->after('dr_cr');
        });
    }

    public function down(): void
    {
        Schema::table('opening_balances', function (Blueprint $table) {
            $table->dropConstrainedForeignId('voucher_id');
            $table->dropColumn(['dr_cr', 'posted_amount']);
        });
    }
};
