package com.fs.live.mapper;


import com.fs.live.domain.LiveLotteryConf;
import com.fs.live.vo.LiveLotteryConfVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

/**
 * 直播抽奖配置Mapper接口
 *
 * @author fs
 * @date 2025-07-17
 */
@Mapper
public interface LiveLotteryConfMapper {
    /**
     * 查询直播抽奖配置
     *
     * @param lotteryId 直播抽奖配置主键
     * @return 直播抽奖配置
     */
    LiveLotteryConf selectLiveLotteryConfByLotteryId(Long lotteryId);

    /**
     * 查询直播抽奖配置列表
     *
     * @param liveLotteryConf 直播抽奖配置
     * @return 直播抽奖配置集合
     */
    List<LiveLotteryConf> selectLiveLotteryConfList(LiveLotteryConf liveLotteryConf);

    /**
     * 新增直播抽奖配置
     *
     * @param liveLotteryConf 直播抽奖配置
     * @return 结果
     */
    int insertLiveLotteryConf(LiveLotteryConf liveLotteryConf);

    /**
     * 修改直播抽奖配置
     *
     * @param liveLotteryConf 直播抽奖配置
     * @return 结果
     */
    int updateLiveLotteryConf(LiveLotteryConf liveLotteryConf);

    /**
     * 删除直播抽奖配置
     *
     * @param lotteryId 直播抽奖配置主键
     * @return 结果
     */
    int deleteLiveLotteryConfByLotteryId(Long lotteryId);

    /**
     * 批量删除直播抽奖配置
     *
     * @param lotteryIds 需要删除的数据主键集合
     * @return 结果
     */
    int deleteLiveLotteryConfByLotteryIds(Long[] lotteryIds);

    @Select("SELECT * FROM live_lottery_conf WHERE lottery_id = #{lotteryId}")
    LiveLotteryConf selectById(Long lotteryId);

    @Select("SELECT * FROM live_lottery_conf WHERE live_id = #{liveId}")
    List<LiveLotteryConf> selectByLiveId(Long liveId);

    @Insert({
            "INSERT INTO live_lottery_conf (live_id,  `require`, " +
                    "require_conf, duration, `desc`, create_time)"+
            "VALUES (#{liveId}, #{require}, " +
                    "#{requireConf}, #{duration}, #{desc},NOW())"})
    @Options(useGeneratedKeys = true, keyProperty = "lotteryId")
    int insert(LiveLotteryConf conf);

    @Update({
            "UPDATE live_lottery_conf SET live_id = #{liveId},`require` = #{require},"+
            "require_conf = #{requireConf}, duration = #{duration}, `desc` = #{desc},"+
            "update_time = NOW() ,lottery_status = #{lotteryStatus}"+
            "WHERE lottery_id = #{lotteryId}"
    })
    void updateAll(LiveLotteryConf conf);

    @Delete("DELETE FROM live_lottery_conf WHERE lottery_id = #{lotteryId}")
    void deleteById(Long lotteryId);

    @Select("SELECT * FROM live_lottery_conf WHERE live_id = #{liveId} AND lottery_status = 1 ")
    List<LiveLotteryConfVo> selectActivedLottery(@Param("liveId") Long liveId);

    List<LiveLotteryConfVo> selectByLotteryIds(@Param("ids") Set<String> ids);

    LiveLotteryConfVo selectLiveLotteryConfVoByLotteryId(@Param("lotteryId") Long lotteryId);

    void finishStatusByLotteryIds(@Param("ids")  List<Long> ids);

    @Select("SELECT * FROM live_lottery_conf WHERE live_id = #{liveId} AND lottery_status = 0 ")
    List<LiveLotteryConf> selectLiveLotteryConfListOn(LiveLotteryConf liveLotteryConf);
}
