<?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('earn_applications', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('collateral_asset_id')->constrained('collateral_assets')->cascadeOnDelete();

            $table->decimal('stake_amount_coin', 30, 8);
            $table->unsignedInteger('duration_days');
            // APR snapshot (fraction form, e.g. 0.12 = 12%).
            $table->decimal('apr_at_submission', 10, 6)->default(0);
            $table->decimal('estimated_returns_usd', 30, 8)->nullable();

            $table->string('status')->default('awaiting_payment_proof');

            $table->string('payout_wallet_address')->nullable();
            $table->string('wallet_provider_name')->nullable();
            $table->string('network')->nullable();
            $table->string('payment_proof_path')->nullable();

            $table->timestamp('submitted_at')->nullable();
            $table->timestamp('payment_proof_submitted_at')->nullable();

            $table->timestamps();
        });
    }

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