package com.yonge.cooleshow.biz.dal.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.microsvc.toolkit.middleware.im.message.GroupMemberWrapper;
import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginService;
import com.yonge.cooleshow.biz.dal.dao.ImGroupDao;
import com.yonge.cooleshow.biz.dal.dto.BasicUserInfo;
import com.yonge.cooleshow.biz.dal.dto.ImGroupResultDto;
import com.yonge.cooleshow.biz.dal.dto.ImGroupSearchDto;
import com.yonge.cooleshow.biz.dal.entity.ImGroup;
import com.yonge.cooleshow.biz.dal.entity.ImGroupMember;
import com.yonge.cooleshow.biz.dal.entity.ImHistoryMessage;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupWrapper;
import io.rong.models.Result;
import com.yonge.cooleshow.biz.dal.enums.RoleEnum;
import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupWrapper;
import io.rong.models.Result;

import java.io.File;
import java.util.List;
import java.util.Set;

/**
 * 即时通讯群组(ImGroup)表服务接口
 *
 * @author zx
 * @since 2022-03-22 10:45:57
 */
public interface ImGroupService extends IService<ImGroup> {

    ImGroupDao getDao();



    /**
     * IM 用户注册
     * @param userId 用户ID
     * @param username 用户名
     * @param avatar 用户头象
     * @return IM聊天Token
     */
    ImGroupWrapper.ImUserInfo register(String userId,ClientEnum clientType, String username, String avatar) throws Exception;

    /**
     * IM 用户注册
     * @param userId 用户Id
     * @return String
     */
    String getImUserId(String userId,String clientType);


    String getImUserId(Long userId, RoleEnum userRole);


    String getImUserId(Long userId, ClientEnum clientEnum);

    /**
     * 解析IM用户规则
     * @param imUserId IM用户Id
     * @return String
     */
    String analysisImUserId(String imUserId);


    /**
     * 检测imUserid
     *
     * @param imUserId IM用户Id
     * @return String
     */
    boolean checkImUserId(String imUserId);

    String analysisImUserClient(String imUserId);

    /**
    * @description: 用户主动创建群聊
     * @param imGroup
    * @author zx
    * @date 2022/3/22 11:17
    */
    String create(ImGroupWrapper.ImGroup imGroup) throws Exception;

    /**
    * @description: 成课后自动创建群聊，建议放在最后执行
     * @param courseGroupId 课程组编号
     * @param courseGroupType 课程组类型
    * @author zx
    * @date 2022/3/22 11:17
    */
    String autoCreate(Long courseGroupId,String courseGroupType) throws Exception;

    List<GroupMemberWrapper.ImGroupMember> getImGroupMembers(List<ImGroupMember> groupMemberList);

    void asyncRegisterUser(List<GroupMemberWrapper.ImGroupMember> groupMembers);

    /**
    * @description: 关闭群聊、解散
     * @param groupId
    * @author zx
    * @date 2022/3/22 11:17
    */
    void dismiss(String groupId) throws Exception;

    /**
    * @description: 获取群列表
     * @param imGroupSearchDto
    * @return java.util.List<com.yonge.cooleshow.biz.dal.entity.ImGroup>
    * @author zx
    * @date 2022/4/27 10:23
    */
    List<ImGroup> queryAll(ImGroupSearchDto imGroupSearchDto);

    /**
    * @description: 获取指定用户创建的群聊
     * @param imGroupSearchDto
    * @return java.util.List<com.yonge.cooleshow.biz.dal.entity.ImGroupResultDto>
    * @author zx
    * @date 2022/4/27 10:56
    */
    List<ImGroupResultDto> queryTeacherFun(ImGroupSearchDto imGroupSearchDto);

    /**
     * 获取课程组的群聊
     *
     * @param courseGroupId 课程组id
     * @return
     */
    ImGroup getByCourseGroupId(Long courseGroupId);

    /**
     * 旧数据创建粉丝群
     */
    void setTeacherFansGroup() throws Exception;

    //退群
    void quit(String groupId, Long userId, ClientEnum clientType,Boolean quit) throws Exception;

    /**
     * 用户群组信息
     * @param groupId 群组ID
     * @param userId 用户ID
     * @return ImGroup
     */
    ImGroup findGroupInfoById(String groupId, Long userId);

    void getAndSaveImHistoryMessage(String date) throws Exception;

    /**
     * 添加群成员
     * @param groupId 群id
     * @param studentIdList 学生成员列表
     */
    void addGroupMember(String groupId, Set<Long> studentIdList) throws Exception;


    /**
     * 同步即时通讯聊天记录
     * @param date
     * @return
     */
    Result historyGet (String date)throws Exception;

    /**
     * 保存历史消息
     * @param file
     */
    void saveImHistoryMessage(File file);


    /**
     * 读取融云数据库信息
     */
    List<ImHistoryMessage> getRongYunInfo(int page,int size);

    /**
     * 导入IM腾讯云
     * @param info
     * @throws Exception
     */
    void importInfo(List<ImHistoryMessage> info) throws Exception;

    /**
     * 群迁移，融云->腾讯
     */
    void groupTransfer();

    void joinImGroup(String roomId, BasicUserInfo userInfo, String serverProvider, List<Long> studentIds) throws Exception;

    /**
     * 用户导入
     */
    void importUser();

    /**
     * 计算未导入数据的总条数
     * @return
     */
    int queryCount();

    /**
     * 更新已修改数据的状态
     * @param info
     */
    void updateStatus(List<ImHistoryMessage> info);

    RTCRoomPluginService getRTCRoomPluginService(String serviceProvider);

    Boolean updateImGroup(ImGroup imGroup);

    void clearImportIm(List<ImHistoryMessage> info);

    void groupAvatarUpdate();

    Boolean muteAll(ImGroupWrapper.Mute mute);
}

