import type { LogEntry, LogLevel } from "../../shared/types";

export class LogStore {
  private entries: LogEntry[] = [];

  add(level: LogLevel, message: string, context?: Record<string, unknown>): LogEntry {
    const entry: LogEntry = {
      id: crypto.randomUUID(),
      level,
      message,
      timestamp: new Date().toISOString(),
      context
    };

    this.entries = [entry, ...this.entries].slice(0, 300);
    return entry;
  }

  list(): LogEntry[] {
    return this.entries;
  }

  clear(): void {
    this.entries = [];
  }
}
