package com.fs.live.mapper;

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


import com.fs.live.domain.LiveRedConf;
import org.apache.ibatis.annotations.*;

/**
 * 直播红包记录配置Mapper接口
 *
 * @author fs
 * @date 2025-07-17
 */
@Mapper
public interface LiveRedConfMapper {
    /**
     * 查询直播红包记录配置
     *
     * @param redId 直播红包记录配置主键
     * @return 直播红包记录配置
     */
    LiveRedConf selectLiveRedConfByRedId(Long redId);

    /**
     * 查询直播红包记录配置列表
     *
     * @param liveRedConf 直播红包记录配置
     * @return 直播红包记录配置集合
     */
    List<LiveRedConf> selectLiveRedConfList(LiveRedConf liveRedConf);

    /**
     * 新增直播红包记录配置
     *
     * @param liveRedConf 直播红包记录配置
     * @return 结果
     */
    int insertLiveRedConf(LiveRedConf liveRedConf);

    /**
     * 修改直播红包记录配置
     *
     * @param liveRedConf 直播红包记录配置
     * @return 结果
     */
    int updateLiveRedConf(LiveRedConf liveRedConf);

    /**
     * 删除直播红包记录配置
     *
     * @param redId 直播红包记录配置主键
     * @return 结果
     */
    int deleteLiveRedConfByRedId(Long redId);

    /**
     * 批量删除直播红包记录配置
     *
     * @param redIds 需要删除的数据主键集合
     * @return 结果
     */
    int deleteLiveRedConfByRedIds(Long[] redIds);

    LiveRedConf selectById(Long redId);

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

    @Insert({
            "INSERT INTO live_red_conf (red_status, duration, red_type, live_id, red_num,"+
            "total_lots, total_send, `desc`, create_time, update_time, create_by, update_by)"+
            "VALUES (#{redStatus}, #{duration}, #{redType}, #{liveId}, #{redNum},"+
            "#{totalLots}, #{totalSend}, #{desc}, NOW(), null, null, null)"
    })
    @Options(useGeneratedKeys = true, keyProperty = "redId")
    int insert(LiveRedConf conf);

    @Update({
            "UPDATE live_red_conf SET red_status = #{redStatus}, duration = #{duration},"+
            "red_type = #{redType}, live_id = #{liveId}, red_num = #{redNum},"+
            "total_lots = #{totalLots}, total_send = #{totalSend}, `desc` = #{desc},"+
            "update_time = NOW()"+
            "WHERE red_id = #{redId}"
    })
    void update(LiveRedConf conf);

    @Delete("DELETE FROM live_red_conf WHERE red_id = #{redId}")
    void deleteById(Long redId);

    @Select("SELECT * FROM live_red_conf WHERE red_status = 1 AND live_id = #{liveId} ")
    List<LiveRedConf> selectActivedRed(@Param("liveId") Long liveId);

    void finishRedStatusBySetIds(@Param("ids") Set<String> ids);

    @Select("SELECT * FROM live_red_conf WHERE live_id=#{liveId}")
    List<LiveRedConf> selectLiveRedConfListOn(LiveRedConf liveRedConf);
}
