"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildHistoryRouter = buildHistoryRouter;
const express_1 = require("express");
const traceLogger_1 = require("../services/traceLogger");
const http_1 = require("../utils/http");
function buildHistoryRouter() {
    const router = (0, express_1.Router)();
    router.get("/api/history", (_req, res) => {
        (0, http_1.ok)(res, {
            ok: true,
            items: (0, traceLogger_1.listTraces)(200)
        });
    });
    router.get("/api/history/:trace_id", (req, res, next) => {
        try {
            const traceId = String(req.params.trace_id);
            const trace = (0, traceLogger_1.getTrace)(traceId);
            if (!trace) {
                throw new http_1.ApiError("TRACE_NOT_FOUND", `Trace not found: ${traceId}`, 404);
            }
            (0, http_1.ok)(res, {
                ok: true,
                trace
            });
        }
        catch (error) {
            next(error);
        }
    });
    return router;
}
