package com.ruoyi.novel.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.novel.domain.VoteRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

// VoteRecordMapper.java
@Mapper
public interface VoteRecordMapper extends BaseMapper<VoteRecord> {

    @Select("SELECT COUNT(*) FROM novel_vote_log " +
            "WHERE user_id = #{userId} AND story_id = #{storyId}")
    int countUserVotesForStory(@Param("userId") Long userId, @Param("storyId") Long storyId);

    @Update("UPDATE novel_vote_log SET notify_status = #{status} WHERE id = #{id}")
    int updateNotifyStatus(@Param("id") Long id, @Param("status") Integer status);

    @Select("SELECT * FROM novel_vote_log WHERE notify_status = 0 ORDER BY vote_time ASC LIMIT 50")
    List<VoteRecord> selectUnnotifiedRecords();
}