import { Injectable } from '@angular/core';

export interface UnknownWidgetDiagnostic {
  tenant: string;
  page: string;
  section: string;
  widget: string;
  reason: string;
}

@Injectable({ providedIn: 'root' })
export class RuntimeDiagnosticsService {
  private readonly unknownWidgetEvents: UnknownWidgetDiagnostic[] = [];

  logUnknownWidget(event: UnknownWidgetDiagnostic): void {
    this.unknownWidgetEvents.unshift(event);
    if (this.unknownWidgetEvents.length > 100) {
      this.unknownWidgetEvents.length = 100;
    }
  }

  getUnknownWidgetEvents(): UnknownWidgetDiagnostic[] {
    return [...this.unknownWidgetEvents];
  }
}
