import 'dart:collection';

import 'package:base_app/data/repository/common_repository.dart';
import 'package:base_app/models/common/banner_model.dart';
import 'package:base_app/models/common/version_model.dart';
import 'package:base_app/res/strings.dart';
import 'package:base_app/utils/http_utils.dart';
import 'package:flustars/flustars.dart';
import 'package:rxdart/rxdart.dart';

import 'bloc_provider.dart';

class MainBloc implements BlocBase {
  ///****** ****** ****** Banner ****** ****** ****** /

  // BehaviorSubject<List<BannerModel>> _banner =
  //     BehaviorSubject<List<BannerModel>>();

  // Sink<List<BannerModel>> get _bannerSink => _banner.sink;

  // Stream<List<BannerModel>> get bannerStream => _banner.stream;

  ///****** ****** ****** 版本号 ****** ****** ****** /

  BehaviorSubject<VersionModel> _version = BehaviorSubject<VersionModel>();

  Sink<VersionModel> get _versionSink => _version.sink;

  Stream<VersionModel> get versionStream => _version.stream.asBroadcastStream();

  VersionModel _versionModel;

  ///****** ****** ****** Version ****** ****** ****** /

  ///****** ****** ****** personal ****** ****** ****** /

  CommonRepository commonRepository = new CommonRepository();

  HttpUtils httpUtils = new HttpUtils();

  MainBloc() {
    LogUtil.e("MainBloc......");
  }

  @override
  Future getData({String labelId, int page}) {
    // switch (labelId) {
    //   case Ids.titleHome:
    //     return getHomeData(labelId);
    //     break;
    //   default:
    //     return Future.delayed(new Duration(seconds: 1));
    //     break;
    // }
  }

  @override
  Future onLoadMore({String labelId}) {}

  @override
  Future onRefresh({String labelId, bool isReload}) {}

  // 获取主页数据
  // Future getHomeData(String labelId) {
  //   return getBanner(labelId);
  // }

  // 获取滚动条幅
  // Future getBanner(String labelId) {
  //   return commonRepository.getBanner().then((list) {
  //     _bannerSink.add(UnmodifiableListView<BannerModel>(list));
  //   });
  // }

  Future getVersion() async {
    httpUtils.getVersion().then((model) {
      _versionModel = model;
      _versionSink.add(_versionModel);
    });
  }

  void test() {
    LogUtil.e("MainBloc test 1.....");
  }

  @override
  void dispose() {
    // _banner.close();
  }
}
