<?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
    {
        // Make lender_company_id nullable in intercompany_loans
        Schema::table('intercompany_loans', function (Blueprint $table) {
            $table->unsignedBigInteger('lender_company_id')->nullable()->change();
        });

        // Make to_company_id nullable in profit_sweep_transactions
        Schema::table('profit_sweep_transactions', function (Blueprint $table) {
            $table->unsignedBigInteger('to_company_id')->nullable()->change();
        });

        // Make parent_company_id nullable in profit_sweep_rules
        Schema::table('profit_sweep_rules', function (Blueprint $table) {
            $table->unsignedBigInteger('parent_company_id')->nullable()->change();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Revert changes - set back to not nullable
        Schema::table('intercompany_loans', function (Blueprint $table) {
            $table->unsignedBigInteger('lender_company_id')->nullable(false)->change();
        });

        Schema::table('profit_sweep_transactions', function (Blueprint $table) {
            $table->unsignedBigInteger('to_company_id')->nullable(false)->change();
        });

        Schema::table('profit_sweep_rules', function (Blueprint $table) {
            $table->unsignedBigInteger('parent_company_id')->nullable(false)->change();
        });
    }
};
