<?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('transactions', function (Blueprint $table) {
            $table->foreignId('category_id')->nullable()->after('account_id')->constrained()->nullOnDelete();
            $table->string('subcategory')->nullable()->after('category');
            $table->string('counterparty_name')->nullable()->after('note');
            $table->string('counterparty_mobile', 20)->nullable()->after('counterparty_name');
            $table->string('purpose', 30)->nullable()->after('counterparty_mobile');
            $table->dateTime('due_at')->nullable()->after('date');
            $table->string('status', 30)->default('posted')->after('direction');
            $table->string('source', 30)->default('manual')->after('status');
            $table->text('input_text')->nullable()->after('source');
        });
    }

    public function down(): void
    {
        Schema::table('transactions', function (Blueprint $table) {
            $table->dropConstrainedForeignId('category_id');
            $table->dropColumn([
                'subcategory',
                'counterparty_name',
                'counterparty_mobile',
                'purpose',
                'due_at',
                'status',
                'source',
                'input_text',
            ]);
        });
    }
};
