package org.agt.module.license.dal.mysql.comment;

import org.agt.framework.mybatis.core.mapper.BaseMapperX;
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.agt.module.license.controller.admin.comment.vo.CommentListReqVO;
import org.agt.module.license.controller.admin.comment.vo.CommentTreeRespVO;
import org.agt.module.license.dal.dataobject.comment.CommentDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 评论 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface CommentMapper extends BaseMapperX<CommentDO> {

    default List<CommentDO> selectList(CommentListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CommentDO>()
                .eqIfPresent(CommentDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(CommentDO::getUserId, reqVO.getUserId())
                .eqIfPresent(CommentDO::getParentId, reqVO.getParentId())
                .eqIfPresent(CommentDO::getContent, reqVO.getContent())
                .betweenIfPresent(CommentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CommentDO::getId));
    }

	default CommentDO selectByParentIdAndContent(Long parentId, String content) {
	    return selectOne(CommentDO::getParentId, parentId, CommentDO::getContent, content);
	}

    default Long selectCountByParentId(Long parentId) {
        return selectCount(CommentDO::getParentId, parentId);
    }

    List<CommentTreeRespVO> getCommentList(@Param("projectId") Long projectId);

    List<CommentTreeRespVO> getLatestCommentList();
}