/**
 * notification-inbox.impl.ts
 * Implementación en memoria del buzón de notificaciones por usuario.
 */

import type {
  InboxNotification,
  NotificationInboxRepository,
} from "../../domain/repositories/notification-inbox.repository.js";

export class InMemoryNotificationInbox implements NotificationInboxRepository {
  private readonly inbox = new Map<number, InboxNotification[]>();

  async addForUser(notification: InboxNotification): Promise<void> {
    const list = this.inbox.get(notification.userId) ?? [];
    list.unshift(notification);
    this.inbox.set(notification.userId, list);
  }

  async getForUser(userId: number): Promise<InboxNotification[]> {
    return this.inbox.get(userId) ?? [];
  }

  async clearForUser(userId: number): Promise<void> {
    this.inbox.delete(userId);
  }

  /** Helper para reset de demo. */
  async clearAll(): Promise<void> {
    this.inbox.clear();
  }
}
