
import 'package:flutter/cupertino.dart';
import 'package:zhiying_base_widget/widgets/home_slide_banner/model/home_slide_banner_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 HomeSlideBannerRepository{

    /// 获取缓存数据
    Future<List<HomeSlideBannerModelItems>> fetchCachedDate({@required int id}) async{
      var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: {'ids': [id]});
      if(!EmptyUtil.isEmpty(cached)){
         HomeSlideBannerModel model =  HomeSlideBannerModel.fromJson(cached);
         if(null != model && !EmptyUtil.isEmpty(model.items)){
           return model.items;
         }
      }
      return null;
    }

    /// 获取数据
    Future<List<HomeSlideBannerModelItems>> fetchData({@required int id}) async{
      var params = await NetUtil.post('/api/v1/mod', params: {'ids': [id]});
      if(NetUtil.isSuccess(params)){
        HomeSlideBannerModel model =  HomeSlideBannerModel.fromJson(params[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
        if(null != model && !EmptyUtil.isEmpty(model.items)){
          return model.items;
        }
      }
      return null;
    }

}
