"use strict";
/**
 * Usage Analytics API Routes
 *
 * Provides REST endpoints for Claude Code usage analytics.
 * Supports daily, monthly, and session-based usage data aggregation.
 *
 * Route handlers are in ./handlers.ts
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.usageRoutes = exports.getLastFetchTimestamp = exports.clearUsageCache = exports.prewarmUsageCache = void 0;
const express_1 = require("express");
const auth_middleware_1 = require("../middleware/auth-middleware");
const handlers_1 = require("./handlers");
var aggregator_1 = require("./aggregator");
Object.defineProperty(exports, "prewarmUsageCache", { enumerable: true, get: function () { return aggregator_1.prewarmUsageCache; } });
Object.defineProperty(exports, "clearUsageCache", { enumerable: true, get: function () { return aggregator_1.clearUsageCache; } });
Object.defineProperty(exports, "getLastFetchTimestamp", { enumerable: true, get: function () { return aggregator_1.getLastFetchTimestamp; } });
exports.usageRoutes = (0, express_1.Router)();
const USAGE_WRITE_ACCESS_ERROR = 'Usage refresh requires localhost access when dashboard auth is disabled.';
exports.usageRoutes.use((req, res, next) => {
    if (req.method.toUpperCase() !== 'POST') {
        next();
        return;
    }
    if ((0, auth_middleware_1.requireLocalAccessWhenAuthDisabled)(req, res, USAGE_WRITE_ACCESS_ERROR)) {
        next();
    }
});
// Summary endpoint
exports.usageRoutes.get('/summary', handlers_1.handleSummary);
// Daily usage endpoint
exports.usageRoutes.get('/daily', handlers_1.handleDaily);
// Hourly usage endpoint
exports.usageRoutes.get('/hourly', handlers_1.handleHourly);
// Models usage endpoint
exports.usageRoutes.get('/models', handlers_1.handleModels);
// Sessions endpoint
exports.usageRoutes.get('/sessions', handlers_1.handleSessions);
// Monthly usage endpoint
exports.usageRoutes.get('/monthly', handlers_1.handleMonthly);
// Cache refresh endpoint
exports.usageRoutes.post('/refresh', handlers_1.handleRefresh);
// Status endpoint
exports.usageRoutes.get('/status', handlers_1.handleStatus);
// Insights endpoint (anomaly detection)
exports.usageRoutes.get('/insights', handlers_1.handleInsights);
//# sourceMappingURL=routes.js.map