package com.cyksj.mapper.manage.coupon;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyksj.model.dto.CouponPopularizeDto;
import com.cyksj.model.entity.Coupon;
import com.cyksj.model.entity.CouponUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Set;

/*
 *项目名: netflix
 *文件名: CouponMapper
 *创建者: JavaZou
 *创建时间:2022/11/17 17:23
 */
public interface CouponMapper extends BaseMapper<Coupon> {
	CouponPopularizeDto checkExCode(String couponExCode);

	@Select("select * from `coupon` where id = #{couponId}")
	Coupon getCouponById(Long couponId);

	@Select("select c.name from coupon c inner join coupon_user cu on cu.coupon_id = c.id where cu.id = #{couponUserId} limit 1")
	String getCouponNameByCouponUserId(Long couponUserId);

	void batchSendCouponToUsers(@Param("userIds") List<Long> userIds, @Param("couponId") Long couponId, @Param("channel") CouponUser.Channel channel, @Param("status") CouponUser.Status status, @Param("validStartTime") Date validStartTime, @Param("validEndTime") Date validEndTime);

	@Select("select name from coupon where id = #{couponId}")
	String getCouponNameById(Long couponId);

	String getCouponNameByIds(List<Long> couponIds);

	Coupon getRenewCouponBySkuId(@Param("skuId") Long skuId, @Param("couponIds") Set<Long> couponIds, @Param("userId") Long userId);

	List<Long> getCouponSkuIds(@Param("couponIds") List<Long> couponIds);
}
