import 'dart:convert';

import 'package:zhiying_base_widget/pages/vip_center_page/model/vip_center_data_model.dart';
import 'package:zhiying_base_widget/pages/vip_center_page/model/vip_center_style_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class VipCenterRepository {
  VipCenterStyleModel _styleModel;
  VipCenterDataModel _dataModel;

  /// 加载缓存Style数据
  Future<dynamic> fetchCachedStyle() async {
    try {
      var result = await NetUtil.getRequestCachedData('/api/v1/mod/pub.flutter.vip_center');
      if (!EmptyUtil.isEmpty(result)) {
        var modListData = result['mod_list'][0]['data'];
        if (!EmptyUtil.isEmpty(modListData)) {
          _styleModel = VipCenterStyleModel.fromJson(jsonDecode(modListData));
          return _styleModel;
        }
      }
    } catch (e, s) {
      Logger.error(e, s);
    }
    return null;
  }

  /// 加载网络Style数据
  Future<dynamic> fetchNetStyle() async {
    try {
      var result = await NetUtil.post('/api/v1/mod/pub.flutter.vip_center', method: NetMethod.GET, cache: true);
      if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
        var modListData = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][0]['data'];
        if (!EmptyUtil.isEmpty(modListData)) {
          _styleModel = VipCenterStyleModel.fromJson(jsonDecode(modListData));
          return _styleModel;
        }
      }
    } catch (e, s) {
      Logger.error(e, s);
    }
    return null;
  }

  /// 加载网络Data数据
  Future<dynamic> fetchNetData() async {
    try {} catch (e, s) {
      Logger.error(e, s);
    }
    return null;
  }
}
