"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerNginxLogRoutes = registerNginxLogRoutes;
const nginx_route_context_1 = require("./nginx-route.context");
function registerNginxLogRoutes(context) {
    const { fastify, nginx } = context;
    fastify.get('/logs/error', async (request, reply) => {
        try {
            const tail = Math.max(1, Math.min(1000, Number(request.query?.tail ?? 100)));
            const lines = await nginx.log.readLogTail('error', tail);
            return reply.send({
                success: true,
                lines,
            });
        }
        catch (error) {
            return (0, nginx_route_context_1.sendBadRequest)(reply, error);
        }
    });
    fastify.get('/logs/access', async (request, reply) => {
        try {
            const tail = Math.max(1, Math.min(1000, Number(request.query?.tail ?? 100)));
            const lines = await nginx.log.readLogTail('access', tail);
            return reply.send({
                success: true,
                lines,
            });
        }
        catch (error) {
            return (0, nginx_route_context_1.sendBadRequest)(reply, error);
        }
    });
    fastify.get('/logs/info', async (_request, reply) => {
        try {
            const errorPath = nginx.log.getLogFilePath('error');
            const accessPath = nginx.log.getLogFilePath('access');
            return reply.send({
                success: true,
                errorLog: errorPath,
                accessLog: accessPath,
            });
        }
        catch (error) {
            return (0, nginx_route_context_1.sendBadRequest)(reply, error);
        }
    });
}
