import { Injectable, signal } from '@angular/core';
import { DiagnosticEntry } from '../models/diagnostics.model';

@Injectable({ providedIn: 'root' })
export class DiagnosticsLoggerService {
  private readonly logsState = signal<DiagnosticEntry[]>([]);

  readonly logs = this.logsState.asReadonly();

  log(entry: DiagnosticEntry): void {
    this.logsState.update(current => [entry, ...current].slice(0, 300));
  }

  clear(): void {
    this.logsState.set([]);
  }
}
