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.LifeDiscountCouponStoreFriend;
import shop.alien.entity.store.vo.LifeDiscountCouponFriendRuleVo;
import shop.alien.entity.store.vo.LifeDiscountCouponStoreFriendVo;
import shop.alien.entity.store.vo.LifeDiscountCouponVo;

import java.util.List;

/**
 * <p>
 * 优惠券商户发放好友优惠券关系表	 Mapper 接口
 * </p>
 *
 * @author ssk
 * @since 2025-02-19
 */
public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDiscountCouponStoreFriend> {

    @Select("select ldc.store_id,ldc.start_date,ldc.end_date,\n" +
            "si.store_name,\n" +
            "ldc.name,ldc.get_status,\n" +
            "ldcsf.single_qty,ldcsf.coupon_id,ldcsf.release_type,ldcsf.id give_coupon_id\n" +
            "from  life_discount_coupon_store_friend ldcsf\n" +
            "left join life_discount_coupon ldc\n" +
            "on ldc.id = ldcsf.coupon_id and ldc.delete_flag = 0\n" +
            "left join store_info si\n" +
            "on si.id = ldc.store_id and si.delete_flag = 0\n" +
            "${ew.customSqlSegment}")
    IPage<LifeDiscountCouponVo> selectPage(IPage<LifeDiscountCouponStoreFriendVo> iPage, @Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponStoreFriendVo> friendLifeDiscountCouponQueryWrapper);

    @Select("select ldcsf.created_time endDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,img.img_url imgUrl,\n" +
            "si.store_name storeName,\n" +
            "ldc.name couponName,\n" +
            "ldc.id couponId,\n" +
            "ldcsf.single_qty couponNum\n" +
            "from  life_discount_coupon_store_friend ldcsf\n" +
            "left join life_discount_coupon ldc\n" +
            "on ldc.id = ldcsf.coupon_id and ldc.delete_flag = 0\n" +
            "left join store_info si\n" +
            "on si.id = ldc.store_id and si.delete_flag = 0\n" +
            "left join store_user su on si.id = su.store_id\n" +
            "left join store_img img on si.id = img.store_id and img.img_type = 1 and img.delete_flag = 0\n" +
            "${ew.customSqlSegment}")
    List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponList(@Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponFriendRuleVo> lifeDiscountCouponFriendRuleVoQueryWrapper);

    //我赠好友
    @Select("select ldcsf.created_time endDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,img.img_url imgUrl,\n" +
            "si.store_name storeName,\n" +
            "ldc.name couponName,\n" +
            "ldc.id couponId,\n" +
            "ldcsf.single_qty couponNum\n" +
            "from  life_discount_coupon_store_friend ldcsf\n" +
            "left join life_discount_coupon ldc\n" +
            "on ldc.id = ldcsf.coupon_id and ldc.delete_flag = 0\n" +

            "left join store_info si\n" +
            "on si.id = ldcsf.store_user_id and si.delete_flag = 0\n" +

            "left join store_user su on ldcsf.store_user_id = su.store_id\n" +

            "left join store_img img on si.id = img.store_id and img.img_type = 1 and img.delete_flag = 0\n" +
            "${ew.customSqlSegment}")
    List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponListwzhy(@Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponFriendRuleVo> lifeDiscountCouponFriendRuleVoQueryWrapper);
}
