﻿using System.Collections.Generic;
namespace ChatSDK
{
    /**
    * The contact manager class, which manages chat contacts such as adding, retrieving, and deleting contacts.
    */
    public abstract class IContactManager
    {

        /**
        * Adds a new contact.
        *
        * This is an asynchronous method.
        * 
        * @param username		The user ID of the contact to add.
        * @param reason     	The invitation message. This parameter is optional and can be set to `null` or "".
        * @param handle	        The result callback. See {@link CallBack}.
        */
        public abstract void AddContact(string username, string reason = null, CallBack handle = null);

        /**
         * Deletes a contact and all the related conversations.
         *
         * This is an asynchronous method.
         *
         * @param username          The user ID of the contact to delete.
         * @param keepConversation  Whether to retain conversations of the contact to delete.
         *                          - `true`: Yes.
   *                                - (Default) `false`: No.
         * @param handle	        The result callback. See {@link CallBack}.
         */
        public abstract void DeleteContact(string username, bool keepConversation = false, CallBack handle = null);

        /**
        * Gets the contact list from the server.
        * 
        * This is an asynchronous method.
        *
        * @param handle The result callback. If success, the SDK returns the list of contacts; if a failure occurs, the SDK returns the error information. See {@link ValueCallBack}.
        */
        public abstract void GetAllContactsFromServer(ValueCallBack<List<string>> handle = null);

        /**
         * Gets the contact list from the local database.
         *
         * @return  If success, the SDK returns the list of contacts; if a failure occurs, the SDK returns an empty list.
         
         */
        public abstract List<string> GetAllContactsFromDB();

        /**
         * Adds a contact to the block list.

         * You can send messages to the users on the block list, but cannot receive messages from them.
         * 
         * This is an asynchronous method.
         *
         * @param username  The user ID of the contact to be added to the block list.
         * @param handle	The result callback. See {@link CallBack}.
         */
        public abstract void AddUserToBlockList(string username, CallBack handle = null);

        /**
         * Removes the contact from the block list.
         * 
         * This is an asynchronous method.
         *
         * @param username  The user ID of the contact to be removed from the block list.
         * @param handle	The result callback. See {@link CallBack}.
         */
        public abstract void RemoveUserFromBlockList(string username, CallBack handle = null);

        /**
         * Gets the block list from the server.
         * 
         * This is an asynchronous method.
         *
         * @param handle    The result callback. If success, the SDK returns the block list; if a failure occurs, the SDK returns the error information. See {@link ValueCallBack}.
         */
        public abstract void GetBlockListFromServer(ValueCallBack<List<string>> handle = null);

        /**
         * Accepts a friend invitation.
         *
         * This an asynchronous method.
         *
         * @param username  The user who initiates the friend invitation.
         * @param handle    The result callback. See {@link CallBack}.
         */
        public abstract void AcceptInvitation(string username, CallBack handle = null);

        /**
         * Declines a friend invitation.
         *      
         * This an asynchronous method.
         *
         * @param username  The user who initiates the friend invitation.
         * @param handle    The result callback. See {@link CallBack}.
         */
        public abstract void DeclineInvitation(string username, CallBack handle = null);

        /**
         * Gets the unique IDs of the current user on the other devices. 
         *
         * The ID is in the format of user ID + "/" + resource.
         *      
         * This is an asynchronous method.
         *
         * @param handle   The result callback. If success, the SDK returns the unique IDs of the current user on the other devices; if a failure occurs, the SDK returns the error information. See {@link ValueCallBack}.
                            
         * 
         */
        public abstract void GetSelfIdsOnOtherPlatform(ValueCallBack<List<string>> handle = null);

        /**
		 * Adds a contact listener.
		 *
		 * @param contactManagerDelegate 		The contact listener to add. It is inherited from {@link IContactManagerDelegate}.
		 * 
		 */
        public void AddContactManagerDelegate(IContactManagerDelegate contactManagerDelegate)
        {
            if (!CallbackManager.Instance().contactManagerListener.delegater.Contains(contactManagerDelegate))
            {
                CallbackManager.Instance().contactManagerListener.delegater.Add(contactManagerDelegate);
            }
        }

        /**
		 * Removes a contact listener.
		 *
		 * @param contactManagerDelegate 		The contact listener to remove. It is inherited from {@link IContactManagerDelegate}.
		 * 
		 */
        public void RemoveContactManagerDelegate(IContactManagerDelegate contactManagerDelegate)
        {
            if (CallbackManager.IsQuit()) return;
            if (CallbackManager.Instance().contactManagerListener.delegater.Contains(contactManagerDelegate))
            {
                CallbackManager.Instance().contactManagerListener.delegater.Remove(contactManagerDelegate);
            }
        }

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

}
