"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = webhookRoutes;
async function webhookRoutes(app, opts) {
    const { webhookHandler } = opts;
    // POST /webhooks/telegram/:botToken — Telegram webhook receiver
    app.post('/webhooks/telegram/:botToken', async (request, reply) => {
        const { botToken } = request.params;
        const update = request.body;
        try {
            const result = await webhookHandler.handleTelegramWebhook(botToken, update);
            if (!result.ok) {
                const status = result.error === 'Invalid bot token' ? 401 : 400;
                return reply.status(status).send({ success: false, error: result.error });
            }
            return reply.status(200).send({ success: true, data: { ok: true } });
        }
        catch (err) {
            return reply.status(500).send({ success: false, error: err.message });
        }
    });
    // POST /webhooks/kie — KIE API webhook receiver
    app.post('/webhooks/kie', async (request, reply) => {
        const payload = request.body;
        try {
            const result = await webhookHandler.handleKIEWebhook(payload);
            if (!result.ok) {
                return reply.status(400).send({ success: false, error: result.error });
            }
            return reply.status(200).send({ success: true, data: { ok: true } });
        }
        catch (err) {
            return reply.status(500).send({ success: false, error: err.message });
        }
    });
}
//# sourceMappingURL=webhooks.js.map