<?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('profile_categories', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable();
            $table->string('status')->nullable();
            $table->string('icon')->nullable(); // Allow for optional icons
            $table->softDeletes(); // For soft deletion
            $table->timestamps();
        });
        Schema::create('profile_groups', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('category_id')->nullable(); // Foreign key
            $table->string('group_name')->nullable();
            $table->text('group_desc')->nullable();
            $table->string('group_status')->nullable();
            $table->timestamps();

            $table->foreign('category_id')->references('id')->on('profile_categories');
        });
        Schema::create('profile_questions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('group_id')->nullable(); // Foreign key
            $table->text('question')->nullable();
            $table->string('type')->nullable(); // e.g., 'text', 'multiple_choice', etc.
            $table->string('status')->nullable();
            $table->timestamps();

            $table->foreign('group_id')->references('id')->on('profile_groups');
        });
        Schema::create('profile_answers', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('category_id')->nullable();
            $table->unsignedBigInteger('group_id')->nullable();
            $table->text('answer')->nullable();
            $table->unsignedBigInteger('patient_id')->nullable();
            $table->unsignedBigInteger('question_id')->nullable();
            $table->timestamps();

            // Foreign Key Constraints
            $table->foreign('category_id')->references('id')->on('profile_categories');
            $table->foreign('group_id')->references('id')->on('profile_groups');
            $table->foreign('patient_id')->references('id')->on('patients'); // Assuming you have a 'patients' table
            $table->foreign('question_id')->references('id')->on('questions');
        });
    }

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