import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart';
import 'package:zhiying_comm/util/net_util.dart';
import 'package:zhiying_comm/util/empty_util.dart';
import 'package:zhiying_comm/util/global_config.dart';

class LoginRepository {
  /// 获取页面数据
  Future<LoginModel> fetchNetPageData() async {
    var result = await NetUtil.post('/api/v1/sign/in', method: NetMethod.GET);
    if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
      LoginModel model = LoginModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
      return model;
    }
    return null;
  }

  /// 获取缓存的页面数据
  Future<LoginModel> fetchCachePageData() async {
    var result = await NetUtil.getRequestCachedData('/api/v1/sign/in');
    if (!EmptyUtil.isEmpty(result)) {
      LoginModel model = LoginModel.fromJson(result);
      return model;
    }
    return null;
  }
}
