/*
 * @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/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();

  final String cookie;
  final int userId;

  ReputationsModel(this.cookie, this.userId);

  init(BuildContext context) {
    if (cookie == null || userId == null) {
      Toast.show(
          context, "传递给flutter参数错误！！ \ncookie:${cookie}  \nuserId:${userId}");
      return;
    }
    Map<String, dynamic> headMap = new Map();
    headMap.putIfAbsent("Cookie", () => cookie);
    DioUtil.addHeadMap = headMap;
    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();
  }
}
