export class NotificationRepository {
    db;
    stmts;
    constructor(db) {
        this.db = db;
        this.stmts = {
            create: db.prepare(`
        INSERT INTO notifications (type, title, message, priority, project_id)
        VALUES (@type, @title, @message, @priority, @project_id)
      `),
            getById: db.prepare('SELECT * FROM notifications WHERE id = ?'),
            delete: db.prepare('DELETE FROM notifications WHERE id = ?'),
            findUnacknowledgedAll: db.prepare('SELECT * FROM notifications WHERE acknowledged = 0 ORDER BY priority DESC, created_at DESC'),
            findUnacknowledgedByProject: db.prepare('SELECT * FROM notifications WHERE acknowledged = 0 AND project_id = ? ORDER BY priority DESC, created_at DESC'),
            acknowledge: db.prepare(`UPDATE notifications SET acknowledged = 1, acknowledged_at = datetime('now') WHERE id = ?`),
        };
    }
    create(data) {
        const result = this.stmts.create.run(data);
        return result.lastInsertRowid;
    }
    getById(id) {
        return this.stmts.getById.get(id);
    }
    delete(id) {
        const result = this.stmts.delete.run(id);
        return result.changes > 0;
    }
    findUnacknowledged(projectId) {
        if (projectId !== undefined) {
            return this.stmts.findUnacknowledgedByProject.all(projectId);
        }
        return this.stmts.findUnacknowledgedAll.all();
    }
    acknowledge(id) {
        const result = this.stmts.acknowledge.run(id);
        return result.changes > 0;
    }
}
//# sourceMappingURL=notification.repository.js.map