<?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('loan_repayments', function (Blueprint $table) {
            $table->string('receipt_path')->nullable()->after('status');
            $table->timestamp('paid_at')->nullable()->after('receipt_path');
            $table->foreignId('paid_by')->nullable()->constrained('users')->onDelete('set null')->after('paid_at');
        });

        Schema::table('profit_sweep_transactions', function (Blueprint $table) {
            $table->string('receipt_path')->nullable()->after('status');
            $table->timestamp('sent_at')->nullable()->after('receipt_path');
            $table->foreignId('sent_by')->nullable()->constrained('users')->onDelete('set null')->after('sent_at');
        });
    }

    public function down(): void
    {
        Schema::table('loan_repayments', function (Blueprint $table) {
            $table->dropColumn(['receipt_path', 'paid_at', 'paid_by']);
        });

        Schema::table('profit_sweep_transactions', function (Blueprint $table) {
            $table->dropColumn(['receipt_path', 'sent_at', 'sent_by']);
        });
    }
};
