using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Muninn.Model;

namespace Unity.Muninn.MuninnLobby
{
    [Serializable]
    public class ListRoomRequest
    {
        public string Namespace;

        [Obsolete] public MuninnLobbyRoomStatus Status;

        public string OwnerId;

        public Int32 Start;

        public Int32 Count;

        public ISet<MuninnLobbyRoomStatus> StatusSet;

        [Obsolete]
        public Dictionary<string, string> ToDictionay()
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            if (!string.IsNullOrWhiteSpace(this.Namespace))
            {
                dict.Add("namespace", this.Namespace);
            }

            if (this.Status != MuninnLobbyRoomStatus.Unknown)
            {
                dict.Add("status", MuninnLobbyRoomStatusHelper.ValueOf(this.Status));
            }

            if (!string.IsNullOrWhiteSpace(this.OwnerId))
            {
                dict.Add("ownerId", this.OwnerId);
            }

            // 这属于分页相关的内容
            if (this.Start != 0)
            {
                dict.Add("start", this.Start.ToString());
            }

            if (this.Count != 0)
            {
                dict.Add("count", this.Count.ToString());
            }

            return dict;
        }

        public string ToParams()
        {
            var parameters = new List<KeyValuePair<string, string>>();

            if (!string.IsNullOrWhiteSpace(Namespace))
            {
                parameters.Add(new KeyValuePair<string, string>("namespace", Namespace));
            }

            if (!string.IsNullOrWhiteSpace(OwnerId))
            {
                parameters.Add(new KeyValuePair<string, string>("ownerId", OwnerId));
            }

            if (StatusSet != null)
            {
                parameters.AddRange(StatusSet.Select(status =>
                    new KeyValuePair<string, string>("status",
                        MuninnLobbyRoomStatusHelper.ValueOf(status))));
            }

            // 这属于分页相关的内容
            if (Start != 0)
            {
                parameters.Add(new KeyValuePair<string, string>("start", Start.ToString()));
            }

            if (Count != 0)
            {
                parameters.Add(new KeyValuePair<string, string>("count", Count.ToString()));
            }

            return string.Join("&", parameters.Select(pair => $"{pair.Key}={pair.Value}"));
        }
    }


    [Serializable]
    public class ListRoomRequestDto
    {
        public string Namespace;

        public string Status;

        public string OwnerId;

        public Int32 Start;

        public Int32 Count;

        public Dictionary<string, string> ToDictionay()
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            if (!string.IsNullOrWhiteSpace(this.Namespace))
            {
                dict.Add("namespace", this.Namespace);
            }

            if (!string.IsNullOrWhiteSpace(this.Status))
            {
                dict.Add("status", this.Status);
            }

            if (!string.IsNullOrWhiteSpace(this.OwnerId))
            {
                dict.Add("ownerId", this.OwnerId);
            }

            // 这属于分页相关的内容
            if (this.Start != 0)
            {
                dict.Add("start", this.Start.ToString());
            }

            if (this.Count != 0)
            {
                dict.Add("count", this.Count.ToString());
            }

            return dict;
        }
    }
}