import { EventEmitter } from 'node:events';
const ALERT_EMITTER_EVENT = 'alert';
export class AlertNotificationService {
    emitter = new EventEmitter();
    alerts = new Map();
    emitAlert(event) {
        const withDefaults = {
            ...event,
            createdAt: event.createdAt ?? new Date(),
            acknowledged: event.acknowledged ?? false
        };
        this.alerts.set(withDefaults.id, withDefaults);
        this.emitter.emit(ALERT_EMITTER_EVENT, withDefaults);
        return withDefaults;
    }
    getAlerts() {
        return Array.from(this.alerts.values()).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
    }
    getActiveAlerts() {
        return this.getAlerts().filter(alert => !alert.acknowledged);
    }
    acknowledgeAlert(alertId) {
        const alert = this.alerts.get(alertId);
        if (!alert) {
            return false;
        }
        if (!alert.acknowledged) {
            alert.acknowledged = true;
            this.alerts.set(alertId, alert);
        }
        return true;
    }
    subscribe(listener) {
        this.emitter.on(ALERT_EMITTER_EVENT, listener);
        return () => {
            this.emitter.off(ALERT_EMITTER_EVENT, listener);
        };
    }
    clear() {
        this.alerts.clear();
    }
}
export const alertNotificationService = new AlertNotificationService();
//# sourceMappingURL=alert-notification-service.js.map