import 'package:zhiying_comm/util/turn_chain/turn_chain_style_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class TurnChainDialogRepository {
  ///
  /// 缓存style Data
  /// 多加一个goods_id 用于区分数据
  Future<bool> cacheData(String goodsId, String provider, String commission, String coupon) async {
    try {
      var result = await NetUtil.post(
        '/api/v1/detail_transition',
        params: {'provider': provider, 'commission': commission, 'coupon_price': coupon, 'goods_id': goodsId},
        method: NetMethod.POST,
        cache: true,
      );
      if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
        Logger.debug('缓存跳转样式成功');
        return true;
      }
    } catch (e, s) {
      Logger.error(e, s);
    }
    return false;
  }

  ///
  /// 获取缓存的data
  /// 多加一个goods_id 用于区分数据
  ///
  Future<TurnChainStyleModel> fetchCacheData(String goodsId, String provider, String commission, String coupon) async {
    try {
      var result = await NetUtil.getRequestCachedData(
        '/api/v1/detail_transition',
        params: {'provider': provider, 'commission': commission, 'coupon_price': coupon, 'goods_id': goodsId},
      );
      if (!EmptyUtil.isEmpty(result)) {
        TurnChainStyleModel model = TurnChainStyleModel.fromJson(result);
        if (!EmptyUtil.isEmpty(model)) {
          return model;
        }
      }
    } catch (e, s) {
      Logger.error(e, s);
    }
    return null;
  }
}
