<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->boolean('is_profit_allocation_payment')->default(false)->after('terms');
            $table->string('allocation_month')->nullable()->after('is_profit_allocation_payment'); // Format: '2024-04'
            $table->boolean('is_loan_request')->default(false)->after('allocation_month');
            $table->foreignId('loan_id')->nullable()->after('is_loan_request')->constrained('intercompany_loans')->nullOnDelete();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->dropForeign(['loan_id']);
            $table->dropColumn(['is_profit_allocation_payment', 'allocation_month', 'is_loan_request', 'loan_id']);
        });
    }
};
