<?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('investors', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->string('email')->unique();
            $table->string('full_name');
            $table->string('phone', 50)->nullable();
            $table->string('country', 100)->nullable();
            $table->enum('investor_type', ['individual', 'company', 'fund', 'family_office', 'institution'])->default('individual');
            $table->decimal('total_invested', 15, 2)->default(0);
            $table->integer('active_investments')->default(0);
            $table->decimal('lifetime_returns', 15, 2)->default(0);
            $table->enum('kyc_status', ['not_started', 'pending', 'approved', 'rejected'])->default('not_started');
            $table->json('kyc_documents')->nullable();
            $table->boolean('pep_status')->default(false);
            $table->boolean('sanctions_checked')->default(false);
            $table->enum('risk_profile', ['conservative', 'moderate', 'aggressive'])->nullable();
            $table->json('communication_preferences')->nullable();
            $table->timestamp('last_login')->nullable();
            $table->boolean('dashboard_access')->default(false);
            $table->timestamps();
        });

        Schema::table('investors', function (Blueprint $table) {
            $table->index('email', 'idx_investor_email');
            $table->index('kyc_status', 'idx_kyc_status');
        });
    }

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