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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.microsvc.toolkit.middleware.im.message.GroupMemberWrapper;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.enums.RoleEnum;
import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupMemberAuditWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupMemberWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupWrapper;

import java.util.List;

/**
 * IM群组服务
 * Created by Eric.Shang on 2022/11/26.
 */
public interface ImGroupCoreService {

    /**
     * IM 用户注册
     * @param userId 用户ID
     * @param username 用户名
     * @param avatar 用户头象
     * @return IM聊天Token
     */
    ImGroupWrapper.ImUserInfo register(String userId,String 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);


    String analysisImUser(String imUserId);

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

    String analysisImUserClient(String imUserId);


    /**
     * 添加群组信息
     *
     * @param groupMember 用户信息
     * @param imGroup     ImGroupWrapper.ImGroup
     * @return Boolean
     * @throws Exception Exception
     */
    String groupCreate(GroupMemberWrapper.ImGroupMember groupMember, ImGroupWrapper.ImGroup imGroup) throws Exception;

    /**
     * 添加群组信息
     * @param imGroups ImGroupWrapper.ImGroup
     * @throws Exception Exception
     */
    void groupCreate(List<ImGroupWrapper.ImGroup> imGroups) throws Exception;

    /**
     * 群组解散
     * @param groupId 群组ID
     * @throws Exception Exception
     */
    void groupDismiss( String groupId) throws Exception;

    /**
     * 用户主动退出群聊
     * @param groupMember 用户信息
     * @param groupId 群组ID
     * @throws Exception Exception
     */
    void groupQuit(GroupMemberWrapper.ImGroupMember groupMember, String groupId,Boolean quit) throws Exception;

    /**
     * 删除IM用户
     *
     * @param imUserIds
     */
    void  accountDelete(List<String> imUserIds);

    void  messageDelete(String imUserId, List<String> toImUserIds);

    /**
     * 用户主动退出群聊
     * @param userId 用户信息
     * @param clientType EClientType
     * @param imGroupId 群组ID
     * @throws Exception Exception
     */
    void groupQuit(Long userId, String clientType, String imGroupId,Boolean quit) throws Exception;

    /**
     * 入群申请消息
     * @param groupMember JwtUserInfo<?>
     * @param memberAudit ImGroupMemberAuditWrapper.ImGroupMemberAudit
     */
    void groupJoinApply(GroupMemberWrapper.ImGroupMember groupMember, ImGroupMemberAuditWrapper.ImGroupMemberAudit memberAudit) throws Exception;

    /**
     * 添加群组成员
     * @param groupId 群组ID
     * @param groupMembers List<ImGroupMemberWrapper.ImGroupMember>
     * @throws Exception Exception
     */
    void saveImGroupMemberList(String groupId, List<ImGroupMemberWrapper.ImGroupMember> groupMembers) throws Exception;

    /**
     * 添加群组成员
     * @param imGroupId 群组主键ID
     * @param groupMembers List<ImGroupMemberWrapper.ImGroupMember>
     * @throws Exception Exception
     */
    void saveImGroupMemberList(Long imGroupId, List<ImGroupMemberWrapper.ImGroupMember> groupMembers) throws Exception;

    /**
     * 群成员加入
     * @param imGroupId 群主ID
     * @param groupMembers 群成员
     * @throws Exception Exception
     */
    void groupMemberJoin(String imGroupId, List<ImGroupMemberWrapper.ImGroupMember> groupMembers) throws Exception;

    /**
     * 入群申请审核
     * @param groupMember JwtUserInfo<?>
     * @param audit ImGroupMemberAuditWrapper.ApplyBatchAudit
     */
    void groupJoinAudit(GroupMemberWrapper.ImGroupMember groupMember, ImGroupMemberAuditWrapper.ApplyBatchAudit audit) throws Exception;

    /**
     * 添加进入群组
     *
     * @param userId 用户ID
     * @param clientType 客户端类型
     * @param imGroupId 群组ID
     */
    void groupJoin(Long userId, String clientType, Long imGroupId) throws Exception;

    /**
     * 转让群主
     *
     * @param groupId 群组ID
     * @param newOwner 新群主
     * @param oldOwner 旧群主
     */
    void changeGroupOwner(String groupId, String newOwner, String oldOwner) throws Exception;

    /**
     * 更新群信息
     * @param groupId 群ID
     * @param groupName 群名称
     * @param faceUrl 群头像
     * @throws Exception Exception
     */
    void modifyGroupInfo(String groupId, String groupName, String faceUrl) throws Exception;

    /**
     * 群成员加入三方IM状态
     * @param groupMemberIds 群成员ID
     * @param groupJoin 加群状态
     */
    void updateGroupMemberJoinStatus(List<Long> groupMemberIds, Boolean groupJoin);

    /**
     * 删除最近私聊消息
     * @param userId 发送用户ID
     * @param toUserId 接收用户ID
     * @return Boolean
     * @throws Exception Exception
     */
    Boolean deletePrivateRecentContact(String userId, String toUserId) throws Exception;

    /**
     * 删除最近群聊消息
     * @param userId 发送用户ID
     * @param groupId 群组ID
     * @return Boolean
     * @throws Exception Exception
     */
    Boolean deleteGroupRecentContact(String userId, String groupId) throws Exception;

    void groupMemberMute(ImGroupMemberWrapper.GroupMemberMute member);

    IPage<ImGroupMemberWrapper.ImGroupMember> imGroupMemberPage(IPage<ImGroupMemberWrapper.ImGroupMember> page, ImGroupMemberWrapper.ImGroupMemberQuery query);

    void groupMemberRole(ImGroupMemberWrapper.GroupMemberRole member);

    /**
     * 获取系统随机默认客服
     * @return String
     */
    String getSysRandomCustomerService();
}
