package com.ruoyi.abuwx.service.impl;

import com.ruoyi.abuwx.domain.UserLike;
import com.ruoyi.abuwx.mapper.UserLikeMapper;
import com.ruoyi.abuwx.service.IUserLikeService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 用户点赞记录Service业务层处理
 *
 * @author lujie
 * @date 2025-02-05
 */
@Service
public class UserLikeServiceImpl implements IUserLikeService
{
    @Autowired
    private UserLikeMapper userLikeMapper;

    /**
     * 查询用户点赞记录
     *
     * @param id 用户点赞记录主键
     * @return 用户点赞记录
     */
    @Override
    public UserLike selectUserLikeById(Long id)
    {
        return userLikeMapper.selectUserLikeById(id);
    }

    /**
     * 查询用户点赞记录列表
     *
     * @param userLike 用户点赞记录
     * @return 用户点赞记录
     */
    @Override
    public List<UserLike> selectUserLikeList(UserLike userLike)
    {
        return userLikeMapper.selectUserLikeList(userLike);
    }

    /**
     * 新增用户点赞记录
     *
     * @param userLike 用户点赞记录
     * @return 结果
     */
    @Override
    public int insertUserLike(UserLike userLike)
    {
        userLike.setCreateTime(DateUtils.getNowDate());
        return userLikeMapper.insertUserLike(userLike);
    }

    /**
     * 修改用户点赞记录
     *
     * @param userLike 用户点赞记录
     * @return 结果
     */
    @Override
    public int updateUserLike(UserLike userLike)
    {
        userLike.setUpdateTime(DateUtils.getNowDate());
        return userLikeMapper.updateUserLike(userLike);
    }

    /**
     * 批量删除用户点赞记录
     *
     * @param ids 需要删除的用户点赞记录主键
     * @return 结果
     */
    @Override
    public int deleteUserLikeByIds(Long[] ids)
    {
        return userLikeMapper.deleteUserLikeByIds(ids);
    }

    /**
     * 删除用户点赞记录信息
     *
     * @param id 用户点赞记录主键
     * @return 结果
     */
    @Override
    public int deleteUserLikeById(Long id)
    {
        return userLikeMapper.deleteUserLikeById(id);
    }

    @Override
    public int unlikeContent(Long userId,Long contentType, Long contentId) {
        return userLikeMapper.unlikeContent(userId,contentType,contentId);
    }

    @Override
    public int likeContent(Long userId, Long contentType, Long contentId) {
        UserLike userLike = new UserLike();
        userLike.setUserId(userId);
        userLike.setContentId(contentId);
        userLike.setContentId(contentId);
        userLike.setCreateTime(new Date());
        return userLikeMapper.insertUserLike(userLike);
    }
}
