package com.fs.live.mapper;

import java.util.List;

import com.fs.live.domain.LiveUserRedRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

/**
 * 直播用户红包记录Mapper接口
 *
 * @author fs
 * @date 2025-07-17
 */
@Mapper
public interface LiveUserRedRecordMapper {
    /**
     * 查询直播用户红包记录
     *
     * @param id 直播用户红包记录主键
     * @return 直播用户红包记录
     */
    LiveUserRedRecord selectLiveUserRedRecordById(Long id);

    /**
     * 查询直播用户红包记录列表
     *
     * @param liveUserRedRecord 直播用户红包记录
     * @return 直播用户红包记录集合
     */
    List<LiveUserRedRecord> selectLiveUserRedRecordList(LiveUserRedRecord liveUserRedRecord);

    /**
     * 新增直播用户红包记录
     *
     * @param liveUserRedRecord 直播用户红包记录
     * @return 结果
     */
    int insertLiveUserRedRecord(LiveUserRedRecord liveUserRedRecord);

    /**
     * 修改直播用户红包记录
     *
     * @param liveUserRedRecord 直播用户红包记录
     * @return 结果
     */
    int updateLiveUserRedRecord(LiveUserRedRecord liveUserRedRecord);

    /**
     * 删除直播用户红包记录
     *
     * @param id 直播用户红包记录主键
     * @return 结果
     */
    int deleteLiveUserRedRecordById(Long id);

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

    @Select("SELECT * FROM live_user_red_record WHERE red_id = #{redId}")
    List<LiveUserRedRecord> selectByRedId(Long redId);

    @Select("SELECT * FROM live_user_red_record WHERE user_id = #{userId}")
    List<LiveUserRedRecord> selectByUserId(Long userId);

    @Insert({
            "INSERT INTO live_user_red_record (red_id, live_id, user_id, integral,"+
            "create_time, update_time, create_by, update_by)"+
            "VALUES (#{redId}, #{liveId}, #{userId}, #{integral}, NOW(), null, null, null)"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(LiveUserRedRecord record);

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

    void insertLiveUserRedRecordBatch(List<LiveUserRedRecord> liveUserRedRecords);
}
