<?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::table('user_activities', function (Blueprint $table): void {
            $table->timestamp('hidden_at')->nullable()->after('created_at');
            $table->foreignId('hidden_by')->nullable()->after('hidden_at')->constrained('users')->nullOnDelete();
            $table->string('hidden_reason', 500)->nullable()->after('hidden_by');
            $table->timestamp('flagged_at')->nullable()->after('hidden_reason');
            $table->foreignId('flagged_by')->nullable()->after('flagged_at')->constrained('users')->nullOnDelete();
            $table->string('flag_reason', 500)->nullable()->after('flagged_by');

            $table->index(['hidden_at'], 'user_activities_hidden_at_idx');
            $table->index(['flagged_at'], 'user_activities_flagged_at_idx');
        });
    }

    public function down(): void
    {
        Schema::table('user_activities', function (Blueprint $table): void {
            $table->dropIndex('user_activities_hidden_at_idx');
            $table->dropIndex('user_activities_flagged_at_idx');
            $table->dropConstrainedForeignId('hidden_by');
            $table->dropConstrainedForeignId('flagged_by');
            $table->dropColumn(['hidden_at', 'hidden_reason', 'flagged_at', 'flag_reason']);
        });
    }
};
