import '../../../../../api/demo/data/demo_talk.dart';
import '../../../../../api/demo/demo_mode.dart';
import '../../../../../api/marianumcloud/talk/chat/get_chat_cache.dart';
import '../../../../../api/marianumcloud/talk/chat/get_chat_response.dart';

class ChatDataProvider {
  Future<void> getChat({
    required String token,
    void Function(GetChatResponse data)? onCacheData,
    void Function(GetChatResponse data)? onNetworkData,
    void Function(Object)? onError,
  }) async {
    if (DemoMode.active) {
      final data = DemoTalk.chat(token);
      onCacheData?.call(data);
      onNetworkData?.call(data);
      return;
    }
    final cache = GetChatCache(
      chatToken: token,
      onCacheData: onCacheData,
      onNetworkData: onNetworkData,
      onError: (e) => onError?.call(e),
    );
    await cache.ready;
  }
}
