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

            // Relation table
            $table->unsignedBigInteger('user_id')->nullable(); // user_id (Agenda Author)
            $table->foreign('user_id')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE');
            $table->unsignedBigInteger('survey_id')->nullable(); // survey_id
            $table->foreign('survey_id')->references('id')->on('surveys')->onUpdate('CASCADE')->onDelete('CASCADE');
            $table->unsignedBigInteger('question_id')->nullable(); // question_id (Agenda Author)
            $table->foreign('question_id')->references('id')->on('question_surveys')->onUpdate('CASCADE')->onDelete('CASCADE');

            $table->string('answer')->nullable();

            $table->unsignedBigInteger("updated_by")->nullable();
            $table->unsignedBigInteger("created_by")->nullable();
            $table->unsignedBigInteger("deleted_by")->nullable();
            $table->softDeletes();

            $table->rememberToken();
            $table->timestamps();
        });
    }

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