import { getConversations, getMessages, deleteConversation } from '../bridge/conversation.js';
export async function conversationRoutes(app, opts) {
    const { db } = opts;
    // GET /api/squads/:squadName/conversations
    app.get('/api/squads/:squadName/conversations', {
        preHandler: [app.requireAuth],
    }, async (request, reply) => {
        const { squadName } = request.params;
        const cursor = request.query.cursor;
        const limit = Math.min(parseInt(request.query.limit ?? '20', 10) || 20, 100);
        const result = getConversations(db, squadName, { limit, cursor });
        return reply.send(result);
    });
    // GET /api/conversations/:id/messages
    app.get('/api/conversations/:id/messages', {
        preHandler: [app.requireAuth],
    }, async (request, reply) => {
        const { id } = request.params;
        const cursor = request.query.cursor;
        const limit = Math.min(parseInt(request.query.limit ?? '50', 10) || 50, 200);
        const result = getMessages(db, id, { limit, cursor });
        return reply.send(result);
    });
    // DELETE /api/conversations/:id
    app.delete('/api/conversations/:id', {
        preHandler: [app.requireAuth],
    }, async (request, reply) => {
        const { id } = request.params;
        const deleted = deleteConversation(db, id);
        if (!deleted) {
            return reply.status(404).send({ error: 'Conversation not found' });
        }
        return reply.send({ ok: true });
    });
}
//# sourceMappingURL=conversations.js.map