<?php

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

return new class extends Migration
{
    /**
     * Adds response_body so ApiLogger can capture what came back from
     * an external call when it fails. Populated only when the response
     * was non-2xx or an exception was thrown — successful responses
     * stay null to keep the table small.
     *
     * Truncated to 65,535 chars (TEXT limit) in code; MEDIUMTEXT gives
     * us headroom for the rare case of a long Anthropic error payload.
     */
    public function up(): void
    {
        Schema::table('api_logs', function (Blueprint $table) {
            $table->mediumText('response_body')
                ->nullable()
                ->after('error')
                ->comment('Response body, populated only on failure. Truncated to ~64KB.');
        });
    }

    public function down(): void
    {
        Schema::table('api_logs', function (Blueprint $table) {
            $table->dropColumn('response_body');
        });
    }
};
