<?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('form_section', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('id_form'); // Foreign key to 'form'
            $table->string('title');
            $table->string('sequence');
            $table->integer('tittle_numbering');
            $table->string('description')->nullable();
            $table->unsignedBigInteger('id_parent_section')->nullable(); // Self-referencing foreign key
            $table->timestamps();

            // Foreign key constraints
            $table->foreign('id_form')->references('id')->on('form')->onDelete('cascade');
            $table->foreign('id_parent_section')->references('id')->on('form_section')->onDelete('set null');
        });
    }

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

