export class MockAutomationLifecycleEmitter {
  private callbacks: Set<(event: unknown) => Promise<void> | void> = new Set()

  onLifecycle(cb: (event: unknown) => Promise<void> | void): void {
    this.callbacks.add(cb)
  }

  offLifecycle(cb: (event: unknown) => Promise<void> | void): void {
    this.callbacks.delete(cb)
  }

  async emit(event: unknown): Promise<void> {
    for (const cb of Array.from(this.callbacks)) {
      try {
        await cb(event)
      } catch {
        // ignore subscriber errors in tests
      }
    }
  }
}