"use strict";
/**
 * Routes Aggregator - Combines all domain-specific route modules
 *
 * This file serves as the central entry point for all API routes,
 * mounting each domain router at its appropriate path.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.apiRoutes = void 0;
const express_1 = require("express");
const auth_middleware_1 = require("../middleware/auth-middleware");
// Import domain routers
const profile_routes_1 = __importDefault(require("./profile-routes"));
const account_routes_1 = __importDefault(require("./account-routes"));
const config_routes_1 = __importDefault(require("./config-routes"));
const health_routes_1 = __importDefault(require("./health-routes"));
const provider_routes_1 = __importDefault(require("./provider-routes"));
const variant_routes_1 = __importDefault(require("./variant-routes"));
const settings_routes_1 = __importDefault(require("./settings-routes"));
const channels_routes_1 = __importDefault(require("./channels-routes"));
const websearch_routes_1 = __importDefault(require("./websearch-routes"));
const image_analysis_routes_1 = __importDefault(require("./image-analysis-routes"));
const browser_routes_1 = __importDefault(require("./browser-routes"));
const cliproxy_auth_routes_1 = __importDefault(require("./cliproxy-auth-routes"));
const cliproxy_stats_routes_1 = __importDefault(require("./cliproxy-stats-routes"));
const cliproxy_routing_routes_1 = __importDefault(require("./cliproxy-routing-routes"));
const cliproxy_sync_routes_1 = __importDefault(require("./cliproxy-sync-routes"));
const ai_provider_routes_1 = __importDefault(require("./ai-provider-routes"));
const copilot_routes_1 = __importDefault(require("./copilot-routes"));
const cursor_routes_1 = __importDefault(require("./cursor-routes"));
const droid_routes_1 = __importDefault(require("./droid-routes"));
const codex_routes_1 = __importDefault(require("./codex-routes"));
const misc_routes_1 = __importDefault(require("./misc-routes"));
const proxy_routes_1 = __importDefault(require("./proxy-routes"));
const auth_routes_1 = __importDefault(require("./auth-routes"));
const persist_routes_1 = __importDefault(require("./persist-routes"));
const catalog_routes_1 = __importDefault(require("./catalog-routes"));
const claude_extension_routes_1 = __importDefault(require("./claude-extension-routes"));
const logs_routes_1 = __importDefault(require("./logs-routes"));
// Create the main API router
exports.apiRoutes = (0, express_1.Router)();
const REMOTE_WRITE_ACCESS_ERROR = 'Remote dashboard writes require localhost access when dashboard auth is disabled.';
function isMutationMethod(method) {
    const normalized = method.toUpperCase();
    return (normalized === 'POST' ||
        normalized === 'PUT' ||
        normalized === 'PATCH' ||
        normalized === 'DELETE');
}
exports.apiRoutes.use((req, res, next) => {
    if (!isMutationMethod(req.method)) {
        next();
        return;
    }
    if ((0, auth_middleware_1.requireLocalAccessWhenAuthDisabled)(req, res, REMOTE_WRITE_ACCESS_ERROR)) {
        next();
    }
});
// ==================== Profile & Settings ====================
// Profile CRUD, settings management, presets, accounts
exports.apiRoutes.use('/profiles', profile_routes_1.default);
exports.apiRoutes.use('/settings', settings_routes_1.default);
exports.apiRoutes.use('/channels', channels_routes_1.default);
exports.apiRoutes.use('/accounts', account_routes_1.default);
// ==================== Unified Config ====================
// Config format, migration
exports.apiRoutes.use('/config', config_routes_1.default);
// ==================== Health Checks ====================
exports.apiRoutes.use('/health', health_routes_1.default);
// ==================== Dashboard Auth ====================
exports.apiRoutes.use('/auth', auth_routes_1.default);
// ==================== Persist (Backup Management) ====================
exports.apiRoutes.use('/persist', persist_routes_1.default);
exports.apiRoutes.use('/claude-extension', claude_extension_routes_1.default);
// ==================== CLIProxy ====================
// Variants, auth, accounts, stats, status, models, error logs
exports.apiRoutes.use('/cliproxy', cliproxy_routing_routes_1.default);
exports.apiRoutes.use('/cliproxy', variant_routes_1.default);
exports.apiRoutes.use('/cliproxy/auth', cliproxy_auth_routes_1.default);
exports.apiRoutes.use('/cliproxy', cliproxy_stats_routes_1.default);
exports.apiRoutes.use('/cliproxy/sync', cliproxy_sync_routes_1.default);
exports.apiRoutes.use('/cliproxy/catalog', catalog_routes_1.default);
exports.apiRoutes.use('/cliproxy/ai-providers', ai_provider_routes_1.default);
exports.apiRoutes.use('/cliproxy/openai-compat', provider_routes_1.default);
// ==================== WebSearch ====================
exports.apiRoutes.use('/websearch', websearch_routes_1.default);
exports.apiRoutes.use('/browser', browser_routes_1.default);
exports.apiRoutes.use('/image-analysis', image_analysis_routes_1.default);
// ==================== Copilot ====================
exports.apiRoutes.use('/copilot', copilot_routes_1.default);
// ==================== Cursor ====================
exports.apiRoutes.use('/cursor', cursor_routes_1.default);
exports.apiRoutes.use('/legacy/cursor', cursor_routes_1.default);
// ==================== Droid ====================
exports.apiRoutes.use('/droid', droid_routes_1.default);
// ==================== Codex ====================
exports.apiRoutes.use('/codex', codex_routes_1.default);
// ==================== CLIProxy Server Settings ====================
exports.apiRoutes.use('/cliproxy-server', proxy_routes_1.default);
// ==================== Misc (File API, Global Env) ====================
exports.apiRoutes.use('/', misc_routes_1.default);
exports.apiRoutes.use('/logs', logs_routes_1.default);
//# sourceMappingURL=index.js.map