/*
 * @author lsy
 * @date   2019-09-04
 **/

import 'package:flutter/cupertino.dart';
import 'package:gmalpha_flutter/commonModel/live/BaseModel.dart';
import 'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart';
import 'package:gmalpha_flutter/commonModel/toast/toast.dart';
import 'package:gmalpha_flutter/userModel/service/UserRepository.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.user.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/UserResultBean.dart';

import '../../../commonModel/live/LiveData.dart';

class UserSettingModel extends BaseModel {
  LiveData<String> nameLive = new LiveData();
  LiveData<String> cityLive = new LiveData();
  LiveData<String> headImgLive = new LiveData();
  LiveData<bool> saveLive = new LiveData();

  final String userid;
  final String refere;

  UserSettingModel(this.userid, this.refere);

  init(BuildContext context) {
    if (UserEntityImpl().getuserId() == null ||
        UserEntityImpl().getuserId() != userid) {
      UserRepository.getInstance().getUserInfo(userid).listen((data) {
        print(data);
      }).onError((error) {
        print(error);
        Toast.show(context, "error");
      });
    } else {
      UserEntityImpl().getnickName().listen((data) {
        nameLive.notifyView(data);
      }).onError((error) {
        print(error);
        Toast.debugShow(context, error);
      });
      UserEntityImpl().getcountryInfoName().listen((data) {
        cityLive.notifyView(data);
      }).onError((error) {
        print(error);
        Toast.debugShow(context, error);
      });
      UserEntityImpl().getprofilePic().listen((value) {
        headImgLive.notifyView(value);
      }).onError((error) {
        print(error);
        Toast.debugShow(context, error);
      });
    }
  }

  @override
  void dispose() {
    nameLive.dispost();
    headImgLive.dispost();
    cityLive.dispost();
    saveLive.dispost();
  }

  void gotoCommentPage(BuildContext context) {}
}
