/**
 * Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
 */
import TelemetryService from './TelemetryService';
import TelemetryConfiguration from './TelemetryConfiguration';
import {IAppender} from '../logger/IAppender';
import {LoggingLevel} from '../logger/Logger';

export default class TelemetryAppender implements IAppender {
  private readonly _telemetryService: TelemetryService;
  private readonly _threshold: LoggingLevel;

  constructor(telemetryConfiguration: TelemetryConfiguration) {
    this._threshold = telemetryConfiguration.threshold;
    this._telemetryService = new TelemetryService(telemetryConfiguration);
  }

  async log(logLevel: LoggingLevel, message: string, category: string, date: Date): Promise<void> {
    if (logLevel < this._threshold) {
      return;
    }

    this._telemetryService.push(logLevel, message, category, date);
  }
}
