package com.xindazhou.business.dal.community.mysql.follow;

import com.xindazhou.business.dal.community.dataobject.follow.FollowDO;
import com.xindazhou.framework.mybatis.core.mapper.BaseMapperX;
import com.xindazhou.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 关注 Mapper
 *
 * @author xindazhou
 */
@Mapper
public interface FollowMapper extends BaseMapperX<FollowDO> {

    /**
     * 查询用户是否已关注
     */
    default FollowDO selectByUserIdAndFollowUserId(Long userId, Long followUserId) {
        return selectOne(new LambdaQueryWrapperX<FollowDO>()
                .eq(FollowDO::getUserId, userId)
                .eq(FollowDO::getFollowUserId, followUserId));
    }

    /**
     * 统计用户的关注数
     */
    default Long selectFollowCount(Long userId) {
        return selectCount(new LambdaQueryWrapperX<FollowDO>()
                .eq(FollowDO::getUserId, userId));
    }

    /**
     * 统计用户的粉丝数
     */
    default Long selectFansCount(Long followUserId) {
        return selectCount(new LambdaQueryWrapperX<FollowDO>()
                .eq(FollowDO::getFollowUserId, followUserId));
    }

}

