using System.Collections.Generic;

namespace ChatSDK
{
    /**
     * \~chinese
     * 在线状态管理类，提供在线状态管理功能。
     *
     * \~english
     * The presence manager class that defines methods of managing the presence state.
     */
    public abstract class IPresenceManager
    {

        /**
         * Publishes a custom presence state.
         *
         * @param ext            The description information of the presence state. It can be an empty string.
         * @param callBack       The result callback which contains the error message if this method fails.
         */
        public abstract void PublishPresence(string description, CallBack handle = null);

        /**
         * Subscribes to a user's presence state. If the subscription succeeds, the subscriber will receive the onPresenceUpdated callback when the user's presence state changes.
         *
         * @param members  The array of user IDs whose presence states you want to subscribe to.
         * @param expiry   The subscription duration in seconds. The duration cannot exceed 2,592,000 (30×24×3600) seconds, i.e., 30 days.
         * @param callBack The result callback which contains the error message if the method fails. Returns the current presence state of subscribed users if this method executes successfully.
         */
        public abstract void SubscribePresences(List<string> members, long expiry, ValueCallBack<List<Presence>> handle = null);

        /**
         * Unsubscribes from the presence state of the unspecified users.
         *
         * @param members  The array of user IDs whose presence state you want to unsubscribe from.
         * @param callBack The result callback, which contains the error message if the method fails.
         */
        public abstract void UnsubscribePresences(List<string> members, CallBack handle = null);

        /**
         * Uses pagination to get the list of users whose presence state you have subscribed to.
         *
         * @param pageNum  The current page number, starting from 1.
         * @param pageSize The number of subscribed users displayed on each page.
         * @param callBack The result callback, which contains user IDs whose presence state you have subscribed to. Returns an empty list if you do not subscribe to any user's presence state.
         */
        public abstract void FetchSubscribedMembers(int pageNum, int pageSize, ValueCallBack<List<string>> handle = null);

        /**
         * Gets the current presence state of the specified users.
         *
         * @param members  The array of user IDs whose current presence state you want to get.
         * @param callBack The result callback, which contains the current presence state of users you have subscribed to.
         */
        public abstract void FetchPresenceStatus(List<string> members, ValueCallBack<List<Presence>> handle = null);

        /**
         * Adds a presence state listener.
         *
         * @param listener {@link IPresenceManagerDelegate} The presence state listener to add.
         */
        public void AddPresenceManagerDelegate(IPresenceManagerDelegate presenceManagerDelegate)
        {
            if (!CallbackManager.Instance().presenceManagerListener.delegater.Contains(presenceManagerDelegate))
            {
                CallbackManager.Instance().presenceManagerListener.delegater.Add(presenceManagerDelegate);
            }
        }

        /**
         * Removes a presence listener.
         *
         * @param listener {@link IPresenceManagerDelegate} The presence state listener to remove.
         */
        public void RemovePresenceManagerDelegate(IPresenceManagerDelegate presenceManagerDelegate)
        {
            if (CallbackManager.IsQuit()) return;
            if (CallbackManager.Instance().presenceManagerListener.delegater.Contains(presenceManagerDelegate))
            {
                CallbackManager.Instance().presenceManagerListener.delegater.Remove(presenceManagerDelegate);
            }
        }

        internal void ClearDelegates()
        {
            CallbackManager.Instance().presenceManagerListener.delegater.Clear();
        }
    }
}
