<?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('enhanced_activity_logs', function (Blueprint $table) {
            // Groups all writes from the same HTTP request together
            $table->char('request_id', 36)->nullable()->after('created_at')->index();
            // Only the first write per request is shown in the DataTable;
            // secondary rows (Variation, etc.) are revealed in the detail modal
            $table->tinyInteger('is_primary')->default(1)->after('request_id');
        });
    }

    public function down(): void
    {
        Schema::table('enhanced_activity_logs', function (Blueprint $table) {
            $table->dropIndex(['request_id']);
            $table->dropColumn(['request_id', 'is_primary']);
        });
    }
};
