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 shop.alien.entity.store.StoreDynamicDiscount;
import shop.alien.entity.store.vo.StoreDynamicDiscountVo;

/**
 * 商户动态折扣 Mapper 接口
 *
 * @author ssk
 * @since 2025-03-18
 */
public interface StoreDynamicDiscountMapper extends BaseMapper<StoreDynamicDiscount> {

    /**
     * 分页查询动态折扣
     *
     * @param page         分页
     * @param queryWrapper 查询条件
     * @return IPage<StoreDynamicDiscountVo>
     */
    @Select("select a.*, b.store_name, c.img_url, " +
            "case a.`status` when 0 then '待审核' when 1 then '已审核' when 2 then '已拒绝' else '塞了个什么几把玩意' end as status_str, " +
            "case a.group_type when 1 then '邀请好友' else '原型没写' end as group_type_str, " +
            "case a.discount_range when 0 then '堂食' when 1 then '外卖' else '商家不接单' end as discount_range_str " +
            "from store_dynamic_discount a " +
            "left join store_info b on a.store_id = b.id " +
            "left join store_img c on a.img_id = c.id and c.img_type = 13 ${ew.customSqlSegment}")
    IPage<StoreDynamicDiscountVo> getPage(IPage<StoreDynamicDiscountVo> page, @Param(Constants.WRAPPER) QueryWrapper<StoreDynamicDiscountVo> queryWrapper);

}
