package com.yc.ship.module.marketing.service.couponCode;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.module.marketing.controller.admin.couponCode.vo.CouponCodePageReqVO;
import com.yc.ship.module.marketing.dal.dataobject.couponCode.CouponCodeDO;
import com.yc.ship.module.marketing.dal.mysql.couponCode.CouponCodeMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;


/**
 * 优惠券码 Service 实现类
 *
 * @author lfy
 */
@Service
@Validated
public class CouponCodeServiceImpl implements CouponCodeService {

    @Resource
    private CouponCodeMapper couponCodeMapper;

    @Override
    public List<CouponCodeDO> getGetNumAndUsedNumList(List<Long> couponIdList) {
        if (CollUtil.isEmpty(couponIdList)) {
            return ListUtil.empty();
        }
        return couponCodeMapper.selectGetAndUsedNumList(couponIdList);
    }

    @Override
    public PageResult<CouponCodeDO> getCouponCodePage(CouponCodePageReqVO pageReqVO) {
        return couponCodeMapper.selectPage(pageReqVO);
    }

    @Override
    public void deleteCouponCode(Long id) {
        couponCodeMapper.deleteById(id);
    }

    @Override
    public CouponCodeDO getCouponCode(Long id) {
        return couponCodeMapper.selectById(id);
    }

    @Override
    public List<CouponCodeDO> getNotUsedCouponCodeList(Long memberId, List<Long> couponIds) {
        if (CollUtil.isEmpty(couponIds)) {
            return Collections.emptyList();
        }
        return couponCodeMapper.selectNotUsedCouponCodeList(memberId,couponIds);
    }
}