import '../../../request_cache.dart';
import 'get_chat.dart';
import 'get_chat_params.dart';
import 'get_chat_response.dart';

class GetChatCache extends SimpleCache<GetChatResponse> {
  GetChatCache({
    super.onCacheData,
    super.onNetworkData,
    super.onError,
    required String chatToken,
  }) : super(
         cacheTime: RequestCache.cacheNothing,
         loader: () => GetChat(
           chatToken,
           GetChatParams(
             lookIntoFuture: GetChatParamsSwitch.off,
             setReadMarker: GetChatParamsSwitch.on,
             // Small initial page; also the per-chat offline snapshot written to
             // localstore. Older messages are paged in on scroll-up via
             // GetChatHistory. Keep in sync with ChatBloc's _kInitialPageSize.
             limit: 50,
           ),
         ).run(),
         fromJson: GetChatResponse.fromJson,
       ) {
    start('nc-chat-$chatToken');
  }
}
