<?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
    {
        if (Schema::hasTable('reports')) {
            return;
        }

        Schema::create('reports', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('reporter_id')->constrained('users')->cascadeOnDelete();
            $table->enum('target_type', ['message', 'conversation', 'user']);
            $table->unsignedBigInteger('target_id');
            $table->string('reason', 120);
            $table->text('details')->nullable();
            $table->enum('status', ['open', 'reviewing', 'closed'])->default('open');
            $table->timestamps();

            $table->index(['target_type', 'target_id']);
            $table->index('status');
            $table->index('reporter_id');
        });
    }

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