"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const assert = __importStar(require("assert"));
const Gateway_1 = require("./orchestrator/Gateway");
async function main() {
    process.env.OPENLIFE_TELEGRAM_ALLOWED_USER_ID = '';
    process.env.OPENLIFE_ENABLE_TTS = 'false';
    const gateway = new Gateway_1.Gateway();
    gateway.classifier = {
        classify: async (_text) => ({ intent: 'KNOWLEDGE_RETRIEVAL', budget: 0.1 })
    };
    gateway.gatekeeper = {
        routeTask: async (_task, _text, _userId) => {
            await new Promise(resolve => setTimeout(resolve, 1200));
            return 'FINAL_AGENT_RESPONSE_FROM_GPT55_PATH';
        }
    };
    const started = Date.now();
    const result = await gateway.processTextForTestDetailed('1344110010', 'ola');
    const totalMs = Date.now() - started;
    assert.ok(result.ackMs !== null, 'ACK_NOT_SENT');
    assert.ok(result.ackMs < 500, `ACK_TOO_SLOW_${result.ackMs}`);
    assert.ok(result.events.length >= 2, `EXPECTED_ACK_AND_FINAL_EVENTS_${JSON.stringify(result.events)}`);
    assert.strictEqual(result.events[0].kind, 'reply', 'FIRST_EVENT_SHOULD_BE_ACK_REPLY');
    assert.ok(result.events[0].text.includes('processando'), `ACK_TEXT_UNEXPECTED_${result.events[0].text}`);
    assert.strictEqual(result.finalText, 'FINAL_AGENT_RESPONSE_FROM_GPT55_PATH', `FINAL_TEXT_UNEXPECTED_${result.finalText}`);
    assert.ok(totalMs >= 1100, 'TEST_STUB_DID_NOT_SIMULATE_SLOW_PATH');
    console.log('TEST_GATEWAY_FAST_ACK_OK');
}
main().catch((err) => {
    console.error('TEST_GATEWAY_FAST_ACK_FAIL:', err?.message || err);
    process.exit(1);
});
