<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Esquema de preguntas extra por tipo de entrada; valores por asistente irán en otra tabla al implementar checkout.
 *
 * @see \App\Models\CustomField
 */
// TODO(regiticket): Tabla `attendee_meta` o columna JSON en `attendees` para almacenar respuestas por `slug`.
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('custom_fields', function (Blueprint $table) {
            $table->id();
            $table->foreignId('ticket_type_id')->constrained('ticket_types')->cascadeOnDelete();
            $table->string('label');
            $table->string('slug');
            $table->string('type', 20);
            $table->json('options')->nullable();
            $table->boolean('required')->default(false);
            $table->unsignedInteger('sort_order')->default(0);
            $table->timestamps();

            $table->unique(['ticket_type_id', 'slug']);
        });
    }

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