<?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('import_entities', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique(); // UI key (plural except person)
            $table->string('canonical_root'); // canonical root for processor (singular)
            $table->string('label');
            $table->json('fields')->nullable(); // array of field names for UI
            $table->json('field_aliases')->nullable(); // map alias -> canonical field
            $table->json('aliases')->nullable(); // array of root aliases (e.g., ["contracts","contract"])
            $table->json('rules')->nullable(); // array of suggestion rules: { pattern, field, priority? }
            $table->json('ui')->nullable(); // optional UI hints (default_field, order, etc.)
            $table->timestamps();
        });
    }

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