package com.mcwl.communityCenter.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcwl.communityCenter.domain.Community;
import com.mcwl.communityCenter.domain.dto.EditCommunityRes;
import com.mcwl.communityCenter.domain.dto.JoinCommunityListPageRes;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

@Mapper
public interface CommunityMapper extends BaseMapper<Community> {
    @InterceptorIgnore(tenantLine = "true")
    Community getByTenantIdAndCommunityId(@NotNull(message = "租户id不能为空")
                                          @Param("tenantId")
                                          Long tenantId,
                                          @NotNull(message = "社区id不能为空")
                                          @Param("communityId")
                                          Long communityId);

    /**
     * 查询所有社区加入人数, 以map形式返回，key为社区id，value为加入人数
     *
     * @return map
     */
    @MapKey("id")
    @InterceptorIgnore(tenantLine = "true")
    Map<Long, Map<String, Object>> selectCommunityJoinNum();

    /**
     * 查询所有社区发布数量，以map形式返回，key为社区id，value为发布数量
     *
     * @return map
     */
    @MapKey("id")
    @InterceptorIgnore(tenantLine = "true")
    Map<Long, Map<String, Object>> selectCommunityPublishNum();

    @InterceptorIgnore(tenantLine = "true")
    List<Community> selectPageByCommunityTag(@Param("page")
                                             Page<Community> page,
                                             @Param("communityTag")
                                             Long communityTag,
                                             @Param("searchContent")
                                             String searchContent);

    @InterceptorIgnore(tenantLine = "true")
    List<Community> getMyJoinCommunity(@Param("page")
                                       Page<Community> page,
                                       @Param("userId")
                                       Long userId,
                                       @Param("joinCommunityListPageRes")
                                       JoinCommunityListPageRes joinCommunityListPageRes);

    @InterceptorIgnore(tenantLine = "true")
    void quitCommunity(@Param("tenantId") Long tenantId,
                       @Param("communityId") Long communityId,
                       @Param("userId") Long userId);

    @InterceptorIgnore(tenantLine = "true")
    void deleteCommunity(@Param("tenantId") Long tenantId, @Param("communityId") Long communityId);

    @InterceptorIgnore(tenantLine = "true")
    Community getCommunity(@Param("tenantId") Long tenantId, @Param("communityId") Long communityId);
}
