import { BUDGET_DEFAULT_USD } from '../../../../../modules/token-accounting/entities/budget/budgetConfig.schema.js';
export const budgetRoutes = async (fastify, opts) => {
    const { getBudgetStatus, updateBudget, budgetGateway, presenter, getRepositories, now } = opts;
    fastify.get('/api/budget', async () => {
        const config = await budgetGateway.load();
        return { limitUsd: config?.limitUsd ?? BUDGET_DEFAULT_USD };
    });
    fastify.post('/api/budget', async (request, reply) => {
        const { limitUsd } = request.body ?? {};
        if (typeof limitUsd !== 'number' || !Number.isFinite(limitUsd)) {
            reply.code(400);
            return { success: false, error: 'limitUsd must be a number' };
        }
        const result = await updateBudget.execute({ limitUsd });
        if (!result.success) {
            reply.code(400);
            return result;
        }
        return result;
    });
    fastify.get('/api/budget/status', async () => {
        const localPaths = getRepositories()
            .filter((repository) => repository.enabled)
            .map((repository) => repository.localPath);
        const status = await getBudgetStatus.execute({
            localPaths,
            now: now ? now() : undefined,
        });
        return presenter.present(status);
    });
};
//# sourceMappingURL=budget.routes.js.map