import { createSSEPresenceAdapter } from '../../presence/index.js';
import { json, internalError, requireAuth } from '../route-helpers.js';
export function registerPresenceRoutes(router) {
    const presenceAdapter = createSSEPresenceAdapter();
    // ---------------------------------------------------------------------------
    // Presence SSE
    // ---------------------------------------------------------------------------
    router.get('/presence/:documentId', async (request, params) => {
        try {
            const auth = await requireAuth(request);
            if (auth.error)
                return auth.error;
            return presenceAdapter.handleSSE(request, params.documentId, {
                userId: auth.session.userId,
                name: auth.session.role,
            });
        }
        catch (err) {
            return internalError(err);
        }
    });
    router.post('/presence/:documentId/heartbeat', async (request, params) => {
        try {
            const auth = await requireAuth(request);
            if (auth.error)
                return auth.error;
            await presenceAdapter.provider.heartbeat(params.documentId, auth.session.userId);
            return json({ data: { ok: true } });
        }
        catch (err) {
            return internalError(err);
        }
    });
}
//# sourceMappingURL=presence.js.map