namespace TeamViewerApi.TeamViewer
{
    using System;
    using System.Net;
    using System.Runtime.Serialization;
    using Newtonsoft.Json;

    [DataContract]
    public class Users
    {
        [DataMember(Name = "users")]
        public User[] Items { get; set; }

        /// <summary>
        /// Get users for the account
        /// </summary>
        /// <param name="accessToken">Token</param>
        public static Users GetUsers(string accessToken, bool fullList = false, string name = "", string email = "")
        {
            string url = TeamViewer.URL.USERS;

            if (fullList)
                url += "?full_list=true";

            if (fullList && !string.IsNullOrEmpty(name))
                url += "&name=" + name;
            else if(!string.IsNullOrEmpty(name))
                url += "?name=" + name;

            if ((fullList || !string.IsNullOrEmpty(name)) && !string.IsNullOrEmpty(email))
                url += "&email=" + email;
            else if (!string.IsNullOrEmpty(email))
                url += "?email=" + email;

            Rest.Properties properties = new Rest.Properties(accessToken, url, Rest.Method.GET);
            Rest.Connection connection = new Rest.Connection(properties);

            string json = connection.SendRequest();

            Users result = null;

            if (!string.IsNullOrEmpty(json))
                result = JsonConvert.DeserializeObject<Users>(json);

            return result;
        }
    }
}
