<?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('partner_distributions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('partner_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('investment_id')->constrained('partner_investments')->cascadeOnDelete();
            $table->foreignId('distribution_id')->constrained('investment_distributions')->cascadeOnDelete();
            $table->integer('shares_owned');
            $table->decimal('distribution_amount', 10, 2);
            $table->enum('payment_method', ['bank_transfer', 'paypal', 'crypto']);
            $table->enum('payment_status', ['pending', 'processed', 'failed'])->default('pending');
            $table->string('payment_reference')->nullable();
            $table->timestamp('processed_at')->nullable();
            $table->timestamps();

            $table->index(['partner_id', 'payment_status']);
        });
    }

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