<?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::create('dividend_payments', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->foreignUuid('investment_id')->constrained('investments')->cascadeOnDelete();
            $table->foreignUuid('investor_id')->constrained('investors')->cascadeOnDelete();
            $table->decimal('amount', 12, 2);
            $table->string('currency', 3)->default('USD');
            $table->integer('quarter')->comment('1-4');
            $table->integer('year');
            $table->enum('status', ['pending', 'processing', 'completed', 'failed'])->default('pending');
            $table->string('payment_method')->nullable()->comment('bank_transfer, paystack, etc.');
            $table->string('transfer_reference')->nullable();
            $table->json('transfer_response')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->text('notes')->nullable();
            $table->timestamps();
        });

        Schema::table('dividend_payments', function (Blueprint $table) {
            $table->index(['investor_id', 'year', 'quarter'], 'idx_investor_period');
            $table->index('status', 'idx_dividend_status');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('dividend_payments');
    }
};
