<?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_mappings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('import_id')->constrained('imports')->cascadeOnDelete();

            // Column/header from the source file and the target field in the system
            $table->string('source_column', 255);
            $table->string('target_field', 255)->nullable();
            $table->string('transform', 50)->nullable(); // e.g., trim|upper|date:dd.MM.yyyy
            $table->json('options')->nullable(); // any extra config for mapping/transforms

            // Indexes
            $table->index(['import_id', 'source_column']);
            $table->index(['import_id', 'target_field']);

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

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