<?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_template_mappings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('import_template_id')->constrained('import_templates')->cascadeOnDelete();

            $table->string('source_column', 255);
            $table->string('target_field', 255)->nullable();
            $table->string('transform', 50)->nullable();
            $table->json('options')->nullable();

            $table->unsignedInteger('position')->nullable(); // order in the header

            $table->timestamps();

            $table->index(['import_template_id', 'source_column']);
            $table->index(['import_template_id', 'position']);
        });
    }

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