<?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('document_data', function (Blueprint $table) {
            $table->unsignedInteger('invoice_title_id')->nullable()->after('invoice_number');
            $table->unsignedInteger('invoice_record_as_id')->nullable()->after('invoice_title_id');
            $table->unsignedInteger('category_id')->nullable()->after('customer_id');
            $table->unsignedInteger('vat_gst_rate_id')->nullable()->after('category_id');
            $table->unsignedInteger('payment_method_id')->nullable()->after('vat_gst_rate_id');
            $table->unsignedInteger('transaction_currency_id')->nullable()->after('currency');
            $table->decimal('exchange_rate', 18, 6)->default(1)->after('transaction_currency_id');
            $table->decimal('vat_amount', 18, 4)->default(0)->after('exchange_rate');
            $table->decimal('net_amount', 18, 4)->default(0)->after('vat_amount');
            $table->decimal('converted_gross_amount', 18, 4)->nullable()->after('net_amount');
            $table->decimal('converted_vat_amount', 18, 4)->nullable()->after('converted_gross_amount');
            $table->decimal('converted_net_amount', 18, 4)->nullable()->after('converted_vat_amount');
            $table->boolean('transaction_missing')->default(false)->after('description');
            $table->boolean('vat_missing')->default(false)->after('transaction_missing');
            $table->boolean('description_missing')->default(false)->after('vat_missing');
            $table->text('additional_options')->nullable()->after('description_missing');
            $table->unsignedBigInteger('data_entry_operator_id')->nullable()->after('additional_options');
            $table->text('notes')->nullable()->after('data_entry_operator_id');
            $table->text('tags')->nullable()->after('notes');
            $table->text('extracted_text')->nullable()->after('tags');
        });
    }

    public function down(): void
    {
        Schema::table('document_data', function (Blueprint $table) {
            $table->dropColumn([
                'invoice_title_id', 'invoice_record_as_id', 'category_id',
                'vat_gst_rate_id', 'payment_method_id', 'transaction_currency_id',
                'exchange_rate', 'vat_amount', 'net_amount', 'converted_gross_amount',
                'converted_vat_amount', 'converted_net_amount', 'transaction_missing',
                'vat_missing', 'description_missing', 'additional_options',
                'data_entry_operator_id', 'notes', 'tags', 'extracted_text',
            ]);
        });
    }
};
