/*
 * @author lsy
 * @date   2019-09-16
 **/
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/PrestigeModel/service/PrestigeRepository.dart';
import 'package:gmalpha_flutter/PrestigeModel/service/remote/entity/PrestigeEntity.dart';
import 'package:gmalpha_flutter/commonModel/base/Temp.dart';
import 'package:gmalpha_flutter/commonModel/live/BaseModel.dart';
import 'package:gmalpha_flutter/commonModel/live/LiveData.dart';
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
import 'package:gmalpha_flutter/commonModel/toast/toast.dart';

class ReputationsModel extends BaseModel {
  LiveData<PrestigeEntity> prestigeLive = new LiveData();
  LiveData<String> titleLive = new LiveData();

  final int userId;
  final String userName;
  final String fromPage;

  ReputationsModel(this.userId, this.userName, this.fromPage);

  start() {
    pageStart("my_expert_reputation", fromPage, DateTime.now().second)
        .listen((value) {
      print("埋点 pageStart 成功？:$value");
    }).onError((error) {
      print(error);
    });
  }

  end() {
    pageEnd("my_expert_reputation", fromPage, DateTime.now().second)
        .listen((value) {
      print("埋点 pageEnd 成功？:$value");
    }).onError((error) {
      print(error);
    });
  }

  init(BuildContext context) {
    titleLive.notifyView(userName);
    PrestigeRepository.getInstance().getReputations(userId).listen((value) {
      if (value != null) {
        prestigeLive.notifyView(value);
      }
    }).onError((error) {
      Toast.show(context, "${error.toString()}");
      print(error);
    });
  }

  @override
  void dispose() {
    prestigeLive.dispost();
    titleLive.dispost();
  }
}
