package com.hwrj.cloud.portal.service.impl;

import com.hwrj.cloud.portal.domain.CartPromotionItem;
import com.hwrj.cloud.portal.domain.SmsCouponHistoryDetail;
import com.hwrj.cloud.portal.model.SmsCoupon;
import com.hwrj.cloud.portal.model.SmsCouponHistory;
import com.hwrj.cloud.portal.model.UmsMember;
import com.hwrj.cloud.portal.service.CouponService;
import com.hwrj.cloud.portal.service.OmsCartItemService;
import com.hwrj.cloud.portal.service.UmsMemberCouponService;
import com.hwrj.cloud.portal.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 会员优惠券管理Service实现类
 * Created by macro on 2018/8/29.
 */
@Service
public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
    @Autowired
    private UmsMemberService memberService;
    @Autowired
    private CouponService couponService;
    @Autowired
    private HttpServletRequest request;

    @Autowired
    private OmsCartItemService cartItemService;


    @Override
    public void add(Long couponId) {
        UmsMember currentMember = memberService.getCurrentMember();
        // 远程接口 添加优惠券
        couponService.add(couponId, currentMember.getId(), currentMember.getNickname());
    }


    @Override
    public List<SmsCoupon> list(Integer useStatus) {
        UmsMember currentMember = memberService.getCurrentMember();
//        CommonResult<List<SmsCoupon>> result = couponService.list(currentMember.getId(), useStatus);
//        if (result.getCode() == ResultCode.SUCCESS.getCode()) {
//            return result.getData();
//        }
        List<SmsCoupon> list = couponService.list(currentMember.getId(), useStatus);
        return list;
    }

    @Override
    public List<SmsCouponHistoryDetail> listCart(Integer type) {
        UmsMember currentMember = memberService.getCurrentMember();
        List<CartPromotionItem> cartPromotionItemList = cartItemService.listPromotion(currentMember.getId(), null);
        List<SmsCouponHistoryDetail> couponHistoryList = couponService.listCart(cartPromotionItemList, currentMember.getId(), type);
//        CommonResult<List<SmsCouponHistoryDetail>> result = couponFeign.listCart(type, currentMember.getId());
//        if (result.getCode() == ResultCode.SUCCESS.getCode()) {
//            return result.getData();
//        }
        return couponHistoryList;
    }

    /**
     * 获取优惠券历史列表
     *
     * @param useStatus
     * @return
     */
    @Override
    public List<SmsCouponHistory> listHistory(Integer useStatus) {
        UmsMember currentMember = memberService.getCurrentMember();
        List<SmsCouponHistory> couponHistoryList = couponService.listHistory(currentMember.getId(), useStatus);
//        CommonResult<List<SmsCouponHistory>> result = couponFeign.listHistory(currentMember.getId(), useStatus);
//        if (result.getCode() == ResultCode.SUCCESS.getCode()) {
//            return result.getData();
//        }
        return couponHistoryList;
    }


}
