import 'package:flutter/foundation.dart';
import '../../models/character_model.dart';

abstract class TtsEngine {
  Future<void> init();

  /// 预连接（可选实现，用于提前建立连接）
  Future<void> preconnect() async {}

  Future<void> speak(
    String text, {
    AiVoiceConfig? voiceConfig,
  });

  Future<void> stop();

  void setStartHandler(VoidCallback handler);

  void setCompletionHandler(VoidCallback handler);

  void setErrorHandler(Function(dynamic) handler);

  void dispose();
}

class TtsEngineException implements Exception {
  final String message;
  final bool isCancelled;

  const TtsEngineException(this.message, {this.isCancelled = false});

  factory TtsEngineException.cancelled() =>
      const TtsEngineException('cancelled', isCancelled: true);

  @override
  String toString() => 'TtsEngineException($message)';
}
