package shop.alien.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.LifeCoupon;
import shop.alien.entity.store.vo.LifeCouponVo;

import java.util.List;

@Mapper
public interface LifeCouponMapper extends BaseMapper<LifeCoupon> {

    @Select("select coupon.id,\n" +
            "coupon.store_id,\n" +
            "coupon.coupon_code,\n" +
            "coupon.`name`,\n" +
            "coupon.price,\n" +
            "coupon.offprice,\n" +
            "coupon.expiration_date,\n" +
            "coupon.start_date,\n" +
            "coupon.end_date,\n" +
            "coupon.unused_date,\n" +
            "coupon.single_qty,\n" +
            "coupon.buy_limit,\n" +
            "coupon.stock_qty,\n" +
            "coupon.use_rule,\n" +
            "coupon.min_use_peoples,\n" +
            "coupon.max_use_peoples,\n" +
            "coupon.dietary_preferences,\n" +
            "coupon.cooking_methods,\n" +
            "coupon.applicable_rule,\n" +
            "coupon.`status`,\n" +
            "coupon.store_service,\n" +
            "coupon.fapiao_info,\n" +
            "coupon.type,\n" +
            "coupon.approval_comments,\n" +
            "coupon.delete_flag,\n" +
            "coupon.created_time,\n" +
            "coupon.updated_time,\n" +
            "coupon.created_user_id,\n" +
            "coupon.updated_user_id,\n" +
            "coupon.open_price_protection,\n" +
            "coupon.price_below,\n" +
            "coupon.coupon_comp,\n" +
            "coupon_comp_date,\n" +
            "coupon.uploaded_picList,\n" +
            "coupon.applicable_num,\n" +
            "coupon.write_off,\n" +
            "coupon.reservation_rules,\n" +
            "coupon.rate_score, store.store_name, store.store_address, user.phone, coupon.created_time, coupon.name, coupon.status " +
            "from life_coupon coupon " +
            "left join store_info store on store.id = coupon.store_id and store.delete_flag = 0 " +
            "left join store_user user on store.id = user.store_id and user.delete_flag = 0 ${ew.customSqlSegment}")
    IPage<LifeCouponVo> getGroupPackageList(IPage<LifeCouponVo> page, @Param(Constants.WRAPPER) QueryWrapper<LifeCouponVo> queryWrapper);

    @Select("SELECT lc.store_id,lc.price FROM life_coupon AS lc LEFT JOIN store_info AS si ON lc.store_id = si.id WHERE si.delete_flag = 0 and si.business_section_name = #{businessSectionName}")
    List<LifeCoupon> selectCoupon(String businessSectionName);

    @Select("SELECT * FROM life_coupon ${ew.customSqlSegment}")
    List<LifeCoupon> getList(@Param(Constants.WRAPPER) LambdaQueryWrapper<LifeCoupon> lambdaQueryWrapper);
}
