<?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('aml_screening_results', function (Blueprint $table) {
            $table->id();
            // Polymorphic — can belong to CompanyRegistration, EmployeeRegistration, or IndividualRegistration
            $table->morphs('screenable');
            // Top-level Dojah fields (stored as columns for easy filtering/sorting)
            $table->string('risk_level')->nullable();    // Low | Medium | High
            $table->string('match_status')->nullable();  // No Match | Potential Match | Confirmed Match
            $table->unsignedInteger('total_results')->default(0);
            $table->unsignedInteger('total_articles')->default(0);
            // Full results array from Dojah as-is (frontend filters by source_type as needed)
            $table->json('results')->nullable();
            // Dojah entity ID echoed back from the response
            $table->string('entity_id')->nullable();
            // Admin who triggered the screening
            $table->foreignId('screened_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamp('screened_at');
            $table->timestamps();
        });
    }

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