import 'dart:convert';

import 'package:zhiying_base_widget/widgets/goods_details/detail_img/model/goods_details_img_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:zhiying_comm/util/taobao/taobao_loader.dart';

class GoodsDetailsImgRepository {
  GoodsDetailsImgModel _model;
  /// 获取父数据
  Future<GoodsDetailsImgModel> fetchParentData(final Map<String, dynamic> model) async {
    try {
      _model = GoodsDetailsImgModel.fromJson(jsonDecode(model['data']));
      if(!EmptyUtil.isEmpty(_model)) {
        return _model;
      }
    } catch (e) {
      Logger.log('GoodsDetailsImgRepository e = $e');
    }
    return null;
  }

  /// 获取网络的数据
  Future<GoodsDetailsImgModel> fetchNetData(final Map<String, dynamic> model) async {
    try {
      if(!EmptyUtil.isEmpty(_model)) {
        List<String> imgs = await TaobaoLoader.loadImages(_model.good_id);
        if(!EmptyUtil.isEmpty(imgs)) {
          return _model.copyWith(_model.image_detail_list + imgs);
        }
      }
    }catch(e){

    }
    return null;
  }
}
