/**
 * Persistent receive cursor.
 *
 * Tracks the highest `received_at` we've consumed from the inbox per
 * (ownAddress, ourSelf-poll context). The InboxClient pulls everything
 * strictly greater than this on each poll.
 *
 * The default in-memory implementation is sufficient for short-lived
 * processes (CLIs, tests). Long-lived services should plug in a SQLite,
 * Postgres, or IndexedDB backed store so a restart doesn't redownload all
 * messages still in TTL.
 */
export interface CursorStore {
  load(address: string): Promise<number>;
  save(address: string, cursor: number): Promise<void>;
}

export class MemoryCursorStore implements CursorStore {
  private cursors = new Map<string, number>();
  async load(address: string): Promise<number> {
    return this.cursors.get(address) ?? 0;
  }
  async save(address: string, cursor: number): Promise<void> {
    this.cursors.set(address, cursor);
  }
}
