import { Router } from 'express';
import * as nc from '../services/notification-center.js';
const router = Router({ mergeParams: true });
router.get('/', (req, res) => {
    const workspaceId = req.params.id;
    res.json(nc.listNotifications(workspaceId));
});
router.post('/', (req, res) => {
    const workspaceId = req.params.id;
    const { type, title, description, data } = req.body;
    if (!type || !title) {
        res.status(400).json({ error: 'type and title are required' });
        return;
    }
    const notification = nc.createNotification(workspaceId, type, title, description, data ?? {});
    res.status(201).json(notification);
});
router.put('/:notificationId/read', (req, res) => {
    const workspaceId = req.params.id;
    const notificationId = req.params.notificationId;
    const n = nc.markRead(workspaceId, notificationId);
    if (!n) {
        res.status(404).json({ error: 'Not found' });
        return;
    }
    res.json(n);
});
router.put('/read-all', (req, res) => {
    const workspaceId = req.params.id;
    const notifications = nc.listNotifications(workspaceId);
    for (const n of notifications)
        nc.markRead(workspaceId, n.id);
    res.json({ ok: true });
});
router.delete('/', (req, res) => {
    const workspaceId = req.params.id;
    nc.clearAll(workspaceId);
    res.json({ ok: true });
});
router.delete('/:notificationId', (req, res) => {
    const workspaceId = req.params.id;
    const notificationId = req.params.notificationId;
    const removed = nc.removeNotification(workspaceId, notificationId);
    if (!removed) {
        res.status(404).json({ error: 'Not found' });
        return;
    }
    res.json({ ok: true });
});
export default router;
//# sourceMappingURL=notification.js.map