package shop.alien.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import shop.alien.entity.store.LifeDiscountCoupon;
import shop.alien.entity.store.vo.LifeDiscountCouponPlatformVo;

/**
 * <p>
 * 优惠券表 Mapper 接口
 * </p>
 *
 * @author ssk
 * @since 2025-02-07
 */
public interface LifeDiscountCouponMapper extends BaseMapper<LifeDiscountCoupon> {

    /**
     * 分页查询优惠券关联店铺
     *
     * @param iPage        分页
     * @param queryWrapper 查询条件
     * @return IPage<LifeDiscountCouponVo>
     */
    @Select("select a.*, b.store_name  from life_discount_coupon a left join store_info b on a.store_id = b.id ${ew.customSqlSegment}")
    IPage<LifeDiscountCouponPlatformVo> selectPageList(IPage<LifeDiscountCouponPlatformVo> iPage, @Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponPlatformVo> queryWrapper);

    /**
     * 查询平台优惠券详情
     *
     * @param id 柱间, 妈的就叫这个吧! 哈西辣妈!
     * @return LifeDiscountCouponPlatformVo
     */
    @Select("select a.*, b.store_name  from life_discount_coupon a left join store_info b on a.store_id = b.id where a.store_id= #{id}")
    LifeDiscountCouponPlatformVo getOnePlatformCoupon(@Param("id") Integer id);


    /**
     * 查询平台优惠券详情
     *
     * @param id
     * @return LifeDiscountCouponPlatformVo
     */
    @Update("UPDATE life_discount_coupon SET single_qty = #{singleQty} where id= #{id}")
    Integer updateCouponById(@Param("id") Integer id, @Param("singleQty") Integer singleQty);
}
