<?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('forum_post_reports', function (Blueprint $table) {
            $table->id();
            $table->foreignId('post_id')->constrained('forum_posts')->cascadeOnDelete();
            $table->foreignId('thread_id')->constrained('forum_threads')->cascadeOnDelete();
            $table->foreignId('reporter_user_id')->constrained('users')->cascadeOnDelete();
            $table->string('status', 20)->default('open');
            $table->string('reason', 500)->nullable();
            $table->string('source_url', 1024)->nullable();
            $table->timestamp('reported_at')->nullable();
            $table->timestamps();

            $table->unique(['post_id', 'reporter_user_id'], 'forum_post_reports_unique_reporter_per_post');
            $table->index(['thread_id', 'status']);
            $table->index('reported_at');
        });
    }

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