import 'dart:typed_data';

import '../../../../../api/demo/data/demo_ticker.dart';
import '../../../../../api/demo/demo_mode.dart';
import '../../../../../api/marianumconnect/queries/get_ticker_page/get_ticker_page.dart';
import '../../../../../api/marianumconnect/queries/get_ticker_page/get_ticker_page_response.dart';
import '../../../../../api/marianumconnect/queries/get_ticker_page_file/get_ticker_page_file.dart';
import '../../../infrastructure/repository/repository.dart';
import '../bloc/ticker_page_state.dart';

/// Split from [TickerRepository] because the loadable base binds a repository
/// to its state type, and the per-page bloc is typed on [TickerPageState].
class TickerPageRepository extends Repository<TickerPageState> {
  Future<TickerPageResponse> getPage(String slug) {
    if (DemoMode.active) return Future.value(DemoTicker.page(slug));
    return GetTickerPage(slug).run();
  }

  Future<Uint8List> getPageFile(String slug) {
    if (DemoMode.active) return Future.value(Uint8List(0));
    return GetTickerPageFile(slug).run();
  }
}
