<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Migration: Forum Thread Read Status Table
 *
 * Tracks per-user read/unread status for forum threads.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('r_forum_thread_reads', function (Blueprint $table) {
            $table->id();

            $table->foreignId('thread_id')
                  ->constrained('r_forum_threads')
                  ->onDelete('cascade');

            $table->foreignId('user_id')
                  ->constrained('users')
                  ->onDelete('cascade');

            $table->boolean('is_read')->default(true)->comment('Read status');
            $table->timestamp('read_at')->nullable()->comment('When last read');

            $table->timestamps();

            $table->unique(['thread_id', 'user_id'], 'r_forum_reads_unique');
            $table->index('user_id');
        });
    }

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