package com.fs.course.mapper;

import java.util.List;
import com.fs.course.domain.FsUserCourseFavorite;
import com.fs.course.param.FsUserCourseListUParam;
import com.fs.course.vo.FsUserCourseFavoriteListUVO;
import com.fs.course.vo.FsUserCourseListUVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 课程收藏Mapper接口
 *
 * @author fs
 * @date 2024-05-15
 */
public interface FsUserCourseFavoriteMapper
{
    /**
     * 查询课程收藏
     *
     * @param favoriteId 课程收藏主键
     * @return 课程收藏
     */
    public FsUserCourseFavorite selectFsUserCourseFavoriteByFavoriteId(Long favoriteId);

    /**
     * 查询课程收藏列表
     *
     * @param fsUserCourseFavorite 课程收藏
     * @return 课程收藏集合
     */
    public List<FsUserCourseFavorite> selectFsUserCourseFavoriteList(FsUserCourseFavorite fsUserCourseFavorite);

    /**
     * 新增课程收藏
     *
     * @param fsUserCourseFavorite 课程收藏
     * @return 结果
     */
    public int insertFsUserCourseFavorite(FsUserCourseFavorite fsUserCourseFavorite);

    /**
     * 修改课程收藏
     *
     * @param fsUserCourseFavorite 课程收藏
     * @return 结果
     */
    public int updateFsUserCourseFavorite(FsUserCourseFavorite fsUserCourseFavorite);

    /**
     * 删除课程收藏
     *
     * @param favoriteId 课程收藏主键
     * @return 结果
     */
    public int deleteFsUserCourseFavoriteByFavoriteId(Long favoriteId);

    /**
     * 批量删除课程收藏
     *
     * @param favoriteIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsUserCourseFavoriteByFavoriteIds(Long[] favoriteIds);


    @Select("select ifnull(count(1),0) from fs_user_course_favorite  where course_id =#{courseId} and user_id=#{userId}")
    int checkFavorite(@Param("courseId") Long courseId, @Param("userId")long userId);


    @Delete("delete from fs_user_course_favorite  where course_id =#{courseId} and user_id=#{userId} ")
    int deleteFavorite(@Param("courseId") Long courseId,@Param("userId")long userId);

    @Select({"<script> " +
            "select c.*,t.nick_name as talent_name,t.avatar,f.favorite_id from fs_user_course_favorite  f" +
            " left join fs_user_course c on c.course_id = f.course_id " +
            " left join fs_user_talent t on t.talent_id = c.talent_id " +
            "where c.is_del = 0  and c.is_show = 1 " +
            "<if test = ' maps.userId !=null '> " +
            "and f.user_id = #{maps.userId} " +
            "</if>" +
            "<if test = ' maps.keyword!=null and maps.keyword != \"\" '> " +
            "and c.course_name like concat('%', #{maps.keyword}, '%') " +
            "or c.description like concat('%', #{maps.keyword}, '%')) " +
            "</if>" +
            " order by f.create_time desc "+
            "</script>"})
    List<FsUserCourseFavoriteListUVO> selectFsUserCourseFavoriteListUVO(@Param("maps") FsUserCourseListUParam param);
}
