import 'package:zhiying_base_widget/pages/team_page/model/team_data_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class TeamRecommendRepository {
  /// 关联我的团队
  Future<TeamDataModel> fetchRelate(String inviteCode) async {
    var data = await NetUtil.post('/api/v1/user/myteam/relate', params: {'invite_code': inviteCode}, method: NetMethod.POST);
    try {
      if (NetUtil.isSuccess(data) && !EmptyUtil.isEmpty(data[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
        return TeamDataModel.fromJson(data[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
      }
    } catch (e, s) {
      Logger.log('e = $e, s = $s');
    }
    return null;
  }

  /// 获取网络数据
  Future<TeamDataModel> fetchNetData() async {
    var data = await NetUtil.post('/api/v1/user/myteam', method: NetMethod.GET);
    try {
      if (NetUtil.isSuccess(data) && !EmptyUtil.isEmpty(data[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
        TeamDataModel _dataModel = TeamDataModel.fromJson(data[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
        return _dataModel;
      }
    } catch (e, s) {
      Logger.log('e = $e, s = $s');
    }
    return null;
  }

}
