/**
 * Example Routes
 * Demonstrates routing patterns
 */
// import { MultiLoginController } from '@app/Controllers/MultiLoginController';
import { Router } from '../src/routes/Router.js';
import { registerMailUiPag } from './mail.js';
import registerDirectMysqlTestRoutes from './TestRoutes.js';
import { JobStateTracker } from '../src/index.js';
const trackerStatuses = new Set([
    'pending',
    'active',
    'completed',
    'failed',
    'stalled',
    'timeout',
    'pending_recovery',
    'dead_letter',
    'manual_review',
    'delayed',
]);
const getQueryValue = (req, key) => {
    const raw = req.getQueryParam(key);
    if (Array.isArray(raw)) {
        return raw.length > 0 ? String(raw[0]) : undefined;
    }
    if (typeof raw === 'string')
        return raw;
    return undefined;
};
const parseLimit = (value) => {
    if (value === undefined || value.trim().length === 0)
        return 200;
    const parsed = Number.parseInt(value, 10);
    if (!Number.isFinite(parsed) || parsed <= 0)
        return 200;
    return Math.min(5000, parsed);
};
const normalizeOptional = (value) => {
    if (value === undefined)
        return undefined;
    const trimmed = value.trim();
    if (trimmed.length === 0)
        return undefined;
    return trimmed;
};
const parseStatus = (value) => {
    const normalized = normalizeOptional(value);
    if (normalized === undefined)
        return undefined;
    if (!trackerStatuses.has(normalized))
        return undefined;
    return normalized;
};
const buildTrackerResponse = (req) => {
    const queueName = normalizeOptional(getQueryValue(req, 'queue'));
    const status = parseStatus(getQueryValue(req, 'status'));
    const jobId = normalizeOptional(getQueryValue(req, 'jobId'));
    const limit = parseLimit(getQueryValue(req, 'limit'));
    const records = JobStateTracker.list({
        queueName,
        status,
        limit,
    });
    const transitions = JobStateTracker.getTransitions({
        queueName,
        jobId,
        limit,
    });
    const processId = typeof process === 'undefined' ? null : process.pid;
    return {
        processId,
        queueName: queueName ?? null,
        status: status ?? null,
        jobId: jobId ?? null,
        limit,
        records,
        transitions,
        summary: JobStateTracker.getSummary(queueName),
        generatedAt: new Date().toISOString(),
    };
};
const registerQueueTrackerDebugRoute = (_router) => {
    Router.get(_router, '/_debug/queue/tracker', async (req, res) => {
        res.json(buildTrackerResponse(req));
    });
};
export function registerDevRoutes(_router) {
    registerDirectMysqlTestRoutes(_router);
    registerQueueTrackerDebugRoute(_router);
    registerMailUiPag(_router);
}
