/*
 * @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/TestUserEntity.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart';

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

class UserPageModel extends BaseModel {
  LiveData<SimpleResponce> logoutLive = new LiveData();
  LiveData<TestUserEntity> resignLive = new LiveData();

//  LiveData<String> userTokenLive = new LiveData();

  UserPageModel() {}

  void logout(BuildContext context) {
    UserRepository.getInstance().logout().listen((data) {
      logoutLive.notifyView(data);
    }).onError((error) {
      Toast.show(context, "error ${error}");
      print(error);
    });
  }

  void resignUser(BuildContext context, String name, String word) {
    UserRepository.getInstance().resignUser(name, word, word).listen((data) {
      print("data !! :${data}");
      resignLive.notifyView(data);
    }).onError((error) {
      Toast.show(context, "error :${error}");
      print(error);
    });
  }

  @override
  void dispose() {
    logoutLive.dispost();
    resignLive.dispost();
  }
}
