﻿using System.Collections.Generic;

namespace ChatSDK
{
/**
	     * The abstract class for the chat manager.
		 * 
	     */
    public abstract class IRoomManager
    {
        /**
	     * Adds a chat room admin.
		 * 
	     * Only the chat room owner can call this method.
	     *
	     * This is an asynchronous method.
	     *
	     * @param chatRoomId	The chat room ID.
	     * @param memberId		The user ID of the chat room admin to be added.
	     * @param handle        The operation result callback. See {@link CallBack}.
	     */
        public abstract void AddRoomAdmin(string roomId, string memberId, CallBack handle = null);

        /**
	     * Adds members to the block list of the chat room.
		 * 
	     * Only the chat room owner or admin can call this method.
		 * 
	     * **Note**
		 * 
	     * - A member, once added to block list of the chat room, will be removed from the chat room by the server.
	     * - After being added to the chat room block list, the member is notified via the {@link IRoomManagerDelegate#OnRemovedFromRoom( String, String, String)} callback.
	     * - Members on the block list cannot rejoin the chat room.
	     *
	     * This is an asynchronous method.
	     *
	     * @param roomId	    The chat room ID.
	     * @param members		The list of members to be added to block list of the chat room.
	     * @param handle        The operation result callback. See {@link CallBack}.
	     */       
        public abstract void BlockRoomMembers(string roomId, List<string> members, CallBack handle = null);

        /**
	     * Transfers the chat room ownership.
		 * 
	     * Only the chat room owner can call this method.
	     *
	     * This is an asynchronous method.
	     *
	     * @param chatRoomId	The chat room ID.
	     * @param newOwner		The user ID of the new chat room owner.
	     * @param handle        The operation result callback. See {@link CallBack}.
	     */
        public abstract void ChangeRoomOwner(string roomId, string newOwner, CallBack handle = null);

        /**
	     * Modifies the chat room description.
		 * 
	     * Only the chat room owner can call this method.
	     *
	     * This is an asynchronous method.
	     *
	     * @param roomId		    The chat room ID.
	     * @param newDescription	The new description of the chat room.
	     * @param handle            The operation result callback. See {@link CallBack}.
	     */
        public abstract void ChangeRoomDescription(string roomId, string newDescription, CallBack handle = null);

        /**
	     * Changes the chat room name.
		 * 
	     * Only the chat room owner can call this method.
	     *
	     * This is an asynchronous method.
	     *
	     * @param roomId	    The chat room ID.
	     * @param newName	    The new name of the chat room.
	     * @param handle        The operation result callback. See {@link CallBack}.
	     */
        public abstract void ChangeRoomName(string roomId, string newName, CallBack handle = null);

        /**
	     * Creates a chat room.
	     *
	     * This is an asynchronous method.
	     *
	     * @param name              The chat room name.
	     * @param description       The chat room description.
	     * @param welcomeMsg        A welcome message inviting members to join the chat room.
	     * @param maxUserCount      The maximum number of members allowed to join the chat room.
	     * @param members           The list of members invited to join the chat room.
	     * @param handle			The operation result callback. See {@link CallBack}.
	     */        
        public abstract void CreateRoom(string name, string descriptions = null, string welcomeMsg = null, int maxUserCount = 300, List<string> members = null, ValueCallBack<Room> handle = null);

		/**
		 * Destroys a chat room.
		 * 
		 * Only the chat room owner can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param handle		The operation result callback. See {@link CallBack}.
		 */
		public abstract void DestroyRoom(string roomId, CallBack handle = null);

		/**
		 * Gets chat room data from the server with pagination.
		 * 
		 * For a large but unknown quantity of data, you can get data with pagination by specifying `pageNum` and `pageSize`.
		 *
		 * This is an asynchronous method.
		 *
		 * @param pageNum 	The page number, starting from 1.
		 * @param pageSize 	The number of records that you expect to get on each page. For the last page, the number of returned records is less than the parameter value.
		 * @param handle	The operation result callback. See {@link CallBack}.
		 * 
		 */		
		public abstract void FetchPublicRoomsFromServer(int pageNum = 1, int pageSize = 200, ValueCallBack<PageResult<Room>> handle = null);

		/**
		 * Gets the chat room announcement from the server.
		 * 
		 * This is an asynchronous method.
		 * 
		 * @param roomId 		The chat room ID.
		 * @param handle		The operation result callback. See {@link CallBack}.
		 */
		public abstract void FetchRoomAnnouncement(string roomId, ValueCallBack<string> handle = null);

		/**
		 * Gets the block list of the chat room with pagination.
         *
         * For a large but unknown quantity of data, you can get data with pagination by specifying `pageSize` and `cursor`.
		 *
		 * Only the chat room owner or admin can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param pageNum		The page number, starting from 1. 
		 * @param pageSize		The number of users on the block list that you expect to get on each page. For the last page, the number of returned users is less than the parameter value.
		 * @param handle		The operation result callback. See {@link CallBack}.
		 *
		 */
		public abstract void FetchRoomBlockList(string roomId, int pageNum = 1, int pageSize = 200, ValueCallBack<List<string>> handle = null);

		/**
		 * Gets details of a chat room from the server, excluding the member list by default.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId	The chat room ID.
		 * @param handle	The operation callback. If success, the chat room instance is returned; otherwise, an error is returned. See {@link ValueCallBack}.
		 */
		public abstract void FetchRoomInfoFromServer(string roomId, ValueCallBack<Room> handle = null);

		/**
		 * Gets the chat room member list with pagination.

		 * For a large but unknown quantity of data, you can get data with pagination by specifying `pageSize` and `cursor`.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param cursor		The cursor position from which to start to get data.
		 *                      At the first method call, if you set `cursor` as `null`, the SDK gets the data in the reverse chronological order of when users joined the chat room. 
		 *                      Amid the returned data (CursorResult), `cursor` is a field saved locally and the updated cursor can be passed as the position from which to start to get data for the next query.
		 * @param pageSize		The number of members that you expect to get on each page. For the last page, the number of returned members is less than the parameter value.
		 * @param handle		The operation callback. If success, the chat room member list is returned; otherwise, an error is returned. See {@link ValueCallBack}.
		 * 
		 */		
		public abstract void FetchRoomMembers(string roomId, string cursor = "", int pageSize = 200, ValueCallBack<CursorResult<string>> handle = null);

		/**
		 * Gets the list of members who are muted in the chat room.
		 *
         * For a large but unknown quantity of data, you can get data with pagination by specifying `pageSize` and `cursor`.
         * 
		 * Only the chat room owner or admin can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param pageNum		The page number, starting from 1.
		 * @param pageSize		The number of muted members that you expect to get on each page. For the last page, the actual number of returned members is less than the parameter value.
		 * @param handle		The operation callback. If success, the chat room mute list is returned; otherwise, an error is returned. See {@link ValueCallBack}.
		 * 
		 */		
		public abstract void FetchRoomMuteList(string roomId, int pageSize = 200, int pageNum = 1, ValueCallBack<List<string>> handle = null);

		/**
		 * Joins the chat room.
		 * 
		 * To exit the chat room, you can call {@link #LeaveRoom(String, CallBack)}.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId 	The ID of the chat room to join.
		 * @param handle	The operation callback. If success, the chat room instance is returned; otherwise, an error is returned. See {@link ValueCallBack}.
		 */		
		public abstract void JoinRoom(string roomId, ValueCallBack<Room> handle = null);

		/**
		 * Leaves a chat room.
		 * 
		 * After joining a chat room via {@link #JoinRoom(String, ValueCallBack)}, the member can call `LeaveRoom` to leave the chat room.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId 	The ID of the chat room to leave.
		 * @param handle	The operation callback. See {@link CallBack}.
		 * 
		 */		
		public abstract void LeaveRoom(string roomId, CallBack handle = null);

		/**
		 * Mutes members in a chat room.
		 * 
		 * Only the chat room owner or admin can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId	The chat room ID.
		 * @param members 	The list of members to be muted.
		 * @param handle	The operation callback. See {@link CallBack}.
		 */		
		public abstract void MuteRoomMembers(string roomId, List<string> members, CallBack handle = null);

		/**
		 * Removes the administrative privileges of a chat room admin.
		 * 
		 * Only the chat room owner can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param adminId		The user ID of the admin whose administrative privileges are to be removed.
		 * @param handle		The operation callback. See {@link CallBack}.
		 */		
		public abstract void RemoveRoomAdmin(string roomId, string adminId, CallBack handle = null);

		/**
		 * Removes members from a chat room.
		 * 
		 * Only the chat room owner or admin can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param members		The list of members to be removed from the chat room.
		 * @param handle		The operation callback. See {@link CallBack}.
		 */
		public abstract void DeleteRoomMembers(string roomId, List<string> members, CallBack handle = null);

		/**
		 * Removes members from the block list of the chat room.
		 * 
		 * Only the chat room owner or admin can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param members		The list of members to be removed from the block list of the chat room.
		 * @param handle		The operation callback. See {@link CallBack}.
		 */
		public abstract void UnBlockRoomMembers(string roomId, List<string> members, CallBack handle = null);

		/**
		 * Unmutes members in a chat room.
		 * 
		 * Only the chat room owner or admin can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId		The chat room ID.
		 * @param members		The list of members to be unmuted.
		 * @param handle		The operation callback. See {@link CallBack}.
		 * 
		 */		
		public abstract void UnMuteRoomMembers(string roomId, List<string> members, CallBack handle = null);

		/**
		 * Updates the chat room announcement.
		 * 
		 * Only the chat room owner or admin can call this method.
		 *
		 * This is an asynchronous method.
		 *
		 * @param roomId 		The chat room ID.
		 * @param announcement 	The announcement content.
		 * @param handle		The operation callback. See {@link CallBack}.
		 * 
		 */
		public abstract void UpdateRoomAnnouncement(string roomId, string announcement, CallBack handle = null);

        /**
         * Mutes all members.
         * Only the chat room owner or admin can call this method.
         * This method does not work for the chat room owner, admin, and members added to the allow list.
         *
         * This is an asynchronous method.
         *
         * @param roomId    The chat room ID.
         * @param handle    The completion callback. If this call succeeds, calls {@link ValueCallBack#onSuccess(Object)};
         *                  if this call fails, calls {@link ValueCallBack#onError(int, String)}.
         */
        public abstract void MuteAllRoomMembers(string roomId, ValueCallBack<Room> handle = null);

        /**
         * Unmutes all members.
         * Only the chat room owner or admin can call this method.
         *
         * This is an asynchronous method.
         *
         * @param roomId    The chat room ID.
         * @param handle    The completion callback. If this call succeeds, calls {@link ValueCallBack#onSuccess(Object)};
         *                  If this call fails, calls {@link ValueCallBack#onError(int, String)}.
         */
        public abstract void UnMuteAllRoomMembers(string roomId, ValueCallBack<Room> handle = null);

        /**
         * Adds members to the allowlist.
         * Only the chat room owner or admin can call this method.
         * For members added to the allowlist, {@link #MuteAllMembers}, when executed by the chat room owner or admin, does not work.
         *
         * This is an asynchronous method.
         *
         * @param roomId       The chat room ID.
         * @param members      The list of members to be added to the allowlist.
         * @param handle       The completion callback. If this call succeeds, calls {@link ValueCallBack#onSuccess(Object)};
         *                     if this call fails, calls {@link ValueCallBack#onError(int, String)}.
         */
        public abstract void AddWhiteListMembers(string roomId, List<string> members, CallBack handle = null);

        /**
         * Removes members from the blocklist.
         * Only the chat room owner or admin can call this method.
         * For members removed from the blocklist, {@link #MuteAllMembers(String, EMValueCallBack)} works.
         *
         * This is an asynchronous method.
         *
         * @param roomId        The chat room ID.
         * @param members       The list of members to be removed from the blocklist.
         * @param handle        The completion callback. If this call succeeds, calls {@link ValueCallBack#onSuccess(Object)};
         *                     if this call fails, calls {@link ValueCallBack#onError(int, String)}.
         */
        public abstract void RemoveWhiteListMembers(string roomId, List<string> members, CallBack handle = null);

		/**
		 * Adds a chat room listener.
		 *
		 * @param roomManagerDelegate 		The chat room listener to add. It is inherited from {@link IRoomManagerDelegate}.
		 * 
		 */
		public void AddRoomManagerDelegate(IRoomManagerDelegate roomManagerDelegate)
        {
            if (!CallbackManager.Instance().roomManagerListener.delegater.Contains(roomManagerDelegate))
            {
                CallbackManager.Instance().roomManagerListener.delegater.Add(roomManagerDelegate);
            }
        }

		/**
		 * Removes a chat room listenter.
		 *
		 * @param roomManagerDelegate 		The chat room listener to remove. It is inherited from {@link IRoomManagerDelegate}.
		 * 
		 */
		public void RemoveRoomManagerDelegate(IRoomManagerDelegate roomManagerDelegate)
        {
            if (CallbackManager.IsQuit()) return;
            if (CallbackManager.Instance().roomManagerListener.delegater.Contains(roomManagerDelegate))
            {
                CallbackManager.Instance().roomManagerListener.delegater.Remove(roomManagerDelegate);
            }            
        }

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