package com.fs.course.service.impl;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.DateUtils;
import com.fs.course.param.FsUserCourseListUParam;
import com.fs.course.vo.FsUserCourseFavoriteListUVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.course.mapper.FsUserCourseFavoriteMapper;
import com.fs.course.domain.FsUserCourseFavorite;
import com.fs.course.service.IFsUserCourseFavoriteService;

/**
 * 课程收藏Service业务层处理
 *
 * @author fs
 * @date 2024-05-15
 */
@Service
public class FsUserCourseFavoriteServiceImpl implements IFsUserCourseFavoriteService
{
    @Autowired
    private FsUserCourseFavoriteMapper fsUserCourseFavoriteMapper;

    /**
     * 查询课程收藏
     *
     * @param favoriteId 课程收藏主键
     * @return 课程收藏
     */
    @Override
    public FsUserCourseFavorite selectFsUserCourseFavoriteByFavoriteId(Long favoriteId)
    {
        return fsUserCourseFavoriteMapper.selectFsUserCourseFavoriteByFavoriteId(favoriteId);
    }

    /**
     * 查询课程收藏列表
     *
     * @param fsUserCourseFavorite 课程收藏
     * @return 课程收藏
     */
    @Override
    public List<FsUserCourseFavorite> selectFsUserCourseFavoriteList(FsUserCourseFavorite fsUserCourseFavorite)
    {
        return fsUserCourseFavoriteMapper.selectFsUserCourseFavoriteList(fsUserCourseFavorite);
    }

    /**
     * 新增课程收藏
     *
     * @param fsUserCourseFavorite 课程收藏
     * @return 结果
     */
    @Override
    public int insertFsUserCourseFavorite(FsUserCourseFavorite fsUserCourseFavorite)
    {
        fsUserCourseFavorite.setCreateTime(DateUtils.getNowDate());
        return fsUserCourseFavoriteMapper.insertFsUserCourseFavorite(fsUserCourseFavorite);
    }

    /**
     * 修改课程收藏
     *
     * @param fsUserCourseFavorite 课程收藏
     * @return 结果
     */
    @Override
    public int updateFsUserCourseFavorite(FsUserCourseFavorite fsUserCourseFavorite)
    {
        fsUserCourseFavorite.setUpdateTime(DateUtils.getNowDate());
        return fsUserCourseFavoriteMapper.updateFsUserCourseFavorite(fsUserCourseFavorite);
    }

    /**
     * 批量删除课程收藏
     *
     * @param favoriteIds 需要删除的课程收藏主键
     * @return 结果
     */
    @Override
    public int deleteFsUserCourseFavoriteByFavoriteIds(Long[] favoriteIds)
    {
        return fsUserCourseFavoriteMapper.deleteFsUserCourseFavoriteByFavoriteIds(favoriteIds);
    }

    /**
     * 删除课程收藏信息
     *
     * @param favoriteId 课程收藏主键
     * @return 结果
     */
    @Override
    public int deleteFsUserCourseFavoriteByFavoriteId(Long favoriteId)
    {
        return fsUserCourseFavoriteMapper.deleteFsUserCourseFavoriteByFavoriteId(favoriteId);
    }

    @Override
    public R checkFavorite(Long courseId, long userId) {
        return fsUserCourseFavoriteMapper.checkFavorite(courseId,userId)>0?R.ok().put("isFavorite",1):R.error().put("isFavorite",0);
    }

    @Override
    public int deleteFavorite(Long courseId, long userId) {
        return fsUserCourseFavoriteMapper.deleteFavorite(courseId,userId);
    }

    @Override
    public List<FsUserCourseFavoriteListUVO> selectFsUserCourseFavoriteListUVO(FsUserCourseListUParam param) {
        return fsUserCourseFavoriteMapper.selectFsUserCourseFavoriteListUVO(param);
    }
}
