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

            // Profile owner (who received the comment)
            $table->unsignedBigInteger('profile_user_id');
            // Who wrote the comment
            $table->unsignedBigInteger('author_user_id');

            $table->text('body');
            $table->boolean('is_active')->default(true);

            $table->timestamps();

            $table->index('profile_user_id', 'idx_pc_profile');
            $table->index('author_user_id', 'idx_pc_author');
            $table->index(['profile_user_id', 'is_active', 'created_at'], 'idx_pc_active_feed');

            $table->foreign('profile_user_id')->references('id')->on('users')->cascadeOnDelete();
            $table->foreign('author_user_id')->references('id')->on('users')->cascadeOnDelete();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('profile_comments');
    }
};
