<?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('respuestas', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('submission_id');
            $table->unsignedBigInteger('pregunta_id');
            $table->text('valor')->nullable();
            $table->unsignedBigInteger('opcion_id')->nullable();
            $table->timestamps();
            $table->foreign('submission_id')->references('id')->on('evaluacion_submissions')->onDelete('cascade');
            $table->foreign('pregunta_id')->references('id')->on('preguntas')->onDelete('cascade');
            $table->foreign('opcion_id')->references('id')->on('pregunta_opciones')->nullOnDelete();
        });
    }
    public function down(): void { Schema::dropIfExists('respuestas'); }
};
