<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('ticket_department_custom_fields', function (Blueprint $table) {
            $table->id();
            $table->foreignId('ticket_department_id')->constrained()->onDelete('cascade');
            $table->string('name');
            $table->enum('type', ['text', 'textarea', 'select', 'checkbox', 'radio', 'email', 'number', 'date']);
            $table->boolean('required')->default(false);
            $table->text('options')->nullable(); // JSON string for select/radio options
            $table->integer('sort_order')->default(0);
            $table->timestamps();

            $table->index(['ticket_department_id', 'sort_order'], 'td_custom_fields_dept_sort_index');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('ticket_department_custom_fields');
    }
};
