package cn.qinys.platform.mobile.mapper;

import cn.qinys.platform.entity.wishing.UserWish;
import cn.qinys.platform.mobile.resp.UserWishSummaryResp;
import cn.qinys.platform.mobile.resp.WishDetailResp;
import cn.qinys.platform.mobile.resp.WishPageResp;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserWishMapper extends BaseMapper<UserWish> {


    @Select("SELECT * FROM user_wish ${ew.customSqlSegment}")
    Page<WishPageResp> selectWishPage(Page<UserWish> page, @Param(Constants.WRAPPER) Wrapper<UserWish> wrapper);


    @Select("SELECT * FROM user_wish WHERE id = #{id}")
    WishDetailResp selectWishDetail(@Param("id") Integer id);


    @Select("SELECT COUNT(*) AS wishCount, SUM(likes) AS receiveCount FROM user_wish " +
            "WHERE user_id = #{userId} AND is_deleted = 0")
    UserWishSummaryResp selectWishSummary(@Param("userId") Integer userId);


    @Select("SELECT  DISTINCT (tree_id) FROM user_wish WHERE  user_id = #{userId} AND is_deleted = 0")
    List<Integer> selectUserTrees(@Param("userId") Integer userId);

}
