package com.fs.live.mapper;

import java.util.List;

import com.fs.live.domain.LiveUserLotteryRecord;
import com.fs.live.vo.LiveUserLotteryRecordVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 直播用户中奖记录Mapper接口
 *
 * @author fs
 * @date 2025-07-17
 */
public interface LiveUserLotteryRecordMapper {
    /**
     * 查询直播用户中奖记录
     *
     * @param id 直播用户中奖记录主键
     * @return 直播用户中奖记录
     */
    LiveUserLotteryRecord selectLiveUserLotteryRecordById(Long id);

    /**
     * 查询直播用户中奖记录列表
     *
     * @param liveUserLotteryRecord 直播用户中奖记录
     * @return 直播用户中奖记录集合
     */
    List<LiveUserLotteryRecord> selectLiveUserLotteryRecordList(LiveUserLotteryRecord liveUserLotteryRecord);

    /**
     * 新增直播用户中奖记录
     *
     * @param liveUserLotteryRecord 直播用户中奖记录
     * @return 结果
     */
    int insertLiveUserLotteryRecord(LiveUserLotteryRecord liveUserLotteryRecord);

    /**
     * 修改直播用户中奖记录
     *
     * @param liveUserLotteryRecord 直播用户中奖记录
     * @return 结果
     */
    int updateLiveUserLotteryRecord(LiveUserLotteryRecord liveUserLotteryRecord);

    /**
     * 删除直播用户中奖记录
     *
     * @param id 直播用户中奖记录主键
     * @return 结果
     */
    int deleteLiveUserLotteryRecordById(Long id);

    /**
     * 批量删除直播用户中奖记录
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    int deleteLiveUserLotteryRecordByIds(Long[] ids);

    @Select("SELECT EXISTS(SELECT 1 FROM live_user_lottery_record WHERE user_id = #{userId} AND red_id = #{redId})")
    boolean existsByUserIdAndRedId(Long lotteryId, String userId);

    List<LiveUserLotteryRecordVo> selectRecordByLiveIdAndLotteryId(LiveUserLotteryRecord liveUserLotteryRecord);

    @Select("select lulr.*,fu.nickname as user_name,fsp.product_name as product_name\n" +
            "        from live_user_lottery_record lulr left join fs_user fu on lulr.user_id = fu.user_id\n" +
            "        " +
            "        left join fs_store_product_scrm fsp on lulr.product_id = fsp.product_id\n" +
            "        where lulr.user_id = #{userId} order by lulr.create_time desc")
    List<LiveUserLotteryRecordVo> selectLiveUserLotteryRecordByUserId(@Param("userId") long userId);

    @Select("update live_user_lottery_record set order_status = #{status} where order_id = #{orderId}")
    void updateOrderStatusByOrderId(@Param("orderId") Long orderId,@Param("status") int status);

}
