package com.fs.live.mapper;

import java.util.List;

import com.fs.live.domain.LiveUserFavorite;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户直播收藏Mapper接口
 *
 * @author fs
 * @date 2025-07-11
 */
public interface LiveUserFavoriteMapper {
    /**
     * 查询用户直播收藏
     *
     * @param favoriteId 用户直播收藏主键
     * @return 用户直播收藏
     */
    LiveUserFavorite selectLiveUserFavoriteByFavoriteId(Long favoriteId);

    /**
     * 查询用户直播收藏列表
     *
     * @param liveUserFavorite 用户直播收藏
     * @return 用户直播收藏集合
     */
    List<LiveUserFavorite> selectLiveUserFavoriteList(LiveUserFavorite liveUserFavorite);

    /**
     * 新增用户直播收藏
     *
     * @param liveUserFavorite 用户直播收藏
     * @return 结果
     */
    int insertLiveUserFavorite(LiveUserFavorite liveUserFavorite);

    /**
     * 修改用户直播收藏
     *
     * @param liveUserFavorite 用户直播收藏
     * @return 结果
     */
    int updateLiveUserFavorite(LiveUserFavorite liveUserFavorite);

    /**
     * 批量删除用户直播收藏
     *
     * @param favoriteIds 需要删除的数据主键集合
     * @return 结果
     */
    int deleteLiveUserFavoriteByFavoriteIds(Long[] favoriteIds);

    LiveUserFavorite selectLiveUserFavoriteByLiveIdAndUserId(@Param("liveId")Long liveId, @Param("userId")Long userId);

    void deleteLiveUserFavoriteByLiveIdAndUserId(@Param("liveId")Long liveId, @Param("userId")Long userId);

    @Select({"<script> " +
            "select count(1) from live_user_favorite where user_id=#{userId} " +
            "<if test=\"productId !=null\">" +
            " and product_id = #{productId}" +
            "</if>" +
            "</script>"})
    long count(@Param("userId") Long userId,@Param("storeId") Long storeId,@Param("productId") Long productId);

    @Delete({"<script> " +
            "delete from live_user_favorite where user_id=#{userId} " +
            "<if test=\"productId !=null\">" +
            " and product_id = #{productId}" +
            "</if>" +"</script>"
    })
    void removeBy(@Param("userId") Long userId,@Param("storeId") Long storeId,@Param("productId") Long productId);

}
