using CrazyStudio.Core.Common.Redis;
using CrazyStudio.Core.Common.Redis.Dto;
using CrazyStudio.Core.Common.Status.Eitities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CrazyStudio.Core.Common.Status.Interfaces
{
    public interface IOnlineUser
    {
        /// <summary>
        /// 添加或者更新用户信息
        /// </summary>
        /// <param name="connectionId">链接ID，唯一</param>
        /// <param name="user">在线用户信息类</param>
        public Task AddOrUpdateUser(string connectionId, OnlineUserInfo user);

        /// <summary>
        /// 根据链接ID移除集合相关用户信息
        /// </summary>
        /// <param name="connectionId">链接ID</param>
        public Task RemoveUserFromId(string connectionId);

        /// <summary>
        /// 根据用户名移除集合相关用户信息
        /// </summary>
        /// <param name="connectionId">链接ID</param>
        public Task RemoveUserFromName(string userName);


        /// <summary>
        /// 根据链接ID获取对应用户名在线用户（唯一）
        /// </summary>
        /// <param name="connectionId">链接ID</param>
        /// <returns>查询到的在线用户信息，找不到就返回空值</returns>
        public OnlineUserInfo? GetUsersFromConnectionId(string connectionId);

        /// <summary>
        /// 发送数据给链接ID对应的链接
        /// </summary>
        /// <param name="userName">链接ID</param>
        /// <param name="packet">要发送的字节数组</param>
        /// <returns></returns>
        public Task<bool> SendMessageToConnection(string connectionId, byte[] packet);


        /// <summary>
        /// 发送数据给链接ID对应的链接,本地没有走集群
        /// </summary>
        /// <param name="userName">链接ID</param>
        /// <param name="packet">要发送的字节数组</param>
        /// <returns></returns>
        public Task SendMessageToUser(string connectionId, string userName, byte[] packet);

        /// <summary>
        /// 发送数据给链接对应用户的链接,本地没有走集群
        /// </summary>
        /// <param name="onlineUser">在线用户对象</param>
        /// <param name="packet">要发送的字节数组</param>
        /// <returns></returns>
        public Task SendMessageToUser(OnlineUserInfo onlineUser, byte[] packet);


        /// <summary>
        /// 发送集群数据给链接ID对应的链接
        /// </summary>
        /// <param name="packet">接收到，要发送的集群数据</param>
        /// <returns></returns>
        public Task SendMessageToConnection(ClusterMessage clusterData);

        /// <summary>
        /// 发送数据给组ID对应的链接
        /// </summary>
        /// <param name="groupOrUserName">组ID</param>
        /// <param name="packet">要发送的字节数组</param>
        /// <returns></returns>
        public Task SendMessageToGroupOrUser(string groupOrUserName, byte[] packet);

        /// <summary>
        /// 发送数据给组ID对应的链接，除了指定的链接ID
        /// </summary>
        /// <param name="groupOrUserName">组ID</param>
        /// <param name="packet">要发送的字节数组</param>
        /// <param name="exceptIds">指定不发送的ConnectionIds</param>
        /// <returns></returns>
        public Task SendMessageToGroupOrUserExceptIds(string groupOrUserName, byte[] packet, HashSet<string> exceptIds);
        public Task RequestHost(OnlineUserInfo userName, bool isRemoveExist = true);

        public Task PushMessageToRoomQueue(string groupOrUserName, string userName, byte[] packet);

    }
}
