<?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::create('forex_import_staging_items', function (Blueprint $table): void {
            $table->id();
            $table->string('status', 24)->default('pending');
            $table->string('row_checksum', 64)->unique();
            $table->unsignedInteger('csv_record_index');
            $table->string('email_hint')->nullable();
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->string('contact_number')->nullable();
            $table->string('country')->nullable();
            $table->string('wallet_address')->nullable();
            $table->decimal('amount', 14, 2);
            $table->unsignedInteger('duration_months');
            $table->timestamp('confirmed_at')->nullable();
            $table->timestamp('maturity_at')->nullable();
            $table->decimal('monthly_return_snapshot', 7, 2);
            $table->json('payload')->nullable();
            $table->foreignId('investment_id')->nullable()->constrained('investments')->nullOnDelete();
            $table->timestamps();

            $table->index(['status', 'created_at']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('forex_import_staging_items');
    }
};
