/**
 * Mock speech transcriber for testing.
 *
 * Returns configurable responses without requiring any speech SDK.
 */

import type { ErrorCallback, FinalCallback, PartialCallback, SpeechTranscriber } from '../types.js';

export class MockSpeechTranscriber implements SpeechTranscriber {
  private _isActive = false;
  private _partialCb: PartialCallback | null = null;
  private _finalCb: FinalCallback | null = null;
  private _errorCb: ErrorCallback | null = null;
  private _vocabulary: string[] = [];

  /** Configurable mock response. */
  public mockTranscript = 'Hello, this is a mock transcript.';
  public mockConfidence = 0.95;

  get isActive(): boolean {
    return this._isActive;
  }

  start(): void {
    this._isActive = true;
  }

  stop(): string {
    this._isActive = false;
    if (this._finalCb) {
      this._finalCb(this.mockTranscript, this.mockConfidence);
    }
    return this.mockTranscript;
  }

  pushAudio(_data: ArrayBuffer | Uint8Array): void {
    if (!this._isActive) return;
    if (this._partialCb) {
      this._partialCb('[Recording...]');
    }
  }

  onPartial(callback: PartialCallback): void {
    this._partialCb = callback;
  }

  onFinal(callback: FinalCallback): void {
    this._finalCb = callback;
  }

  onError(callback: ErrorCallback): void {
    this._errorCb = callback;
  }

  setVocabulary(phrases: string[]): void {
    this._vocabulary = phrases;
  }

  /** Simulate an error (for testing). */
  simulateError(message: string): void {
    if (this._errorCb) {
      this._errorCb(new Error(message));
    }
  }

  /** Get the configured vocabulary (for test assertions). */
  getVocabulary(): string[] {
    return this._vocabulary;
  }
}
