<?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('voucher_lines', function (Blueprint $table) {
            if (!Schema::hasColumn('voucher_lines', 'party_id')) {
                $table->unsignedBigInteger('party_id')->nullable()->after('dr_cr');
            }
            if (!Schema::hasColumn('voucher_lines', 'party_type')) {
                $table->string('party_type', 50)->nullable()->after('party_id');
            }
        });
    }

    public function down(): void
    {
        Schema::table('voucher_lines', function (Blueprint $table) {
            if (Schema::hasColumn('voucher_lines', 'party_type')) {
                $table->dropColumn('party_type');
            }
            if (Schema::hasColumn('voucher_lines', 'party_id')) {
                $table->dropColumn('party_id');
            }
        });
    }
};
