<?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_templates', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();

            $table->string('name', 100);
            $table->string('description', 255)->nullable();

            // What kind of source this template is for (csv|xml|xls|xlsx|json)
            $table->string('source_type', 12)->default('csv');

            // Defaults for records handled by this template (e.g., person, account)
            $table->string('default_record_type', 50)->nullable();

            // Optional sample header row for UI assistance
            $table->json('sample_headers')->nullable();

            // Ownership and lifecycle
            $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->boolean('is_active')->default(true);
            $table->json('meta')->nullable();

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

            $table->index(['source_type', 'is_active']);
        });
    }

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