using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using EQNetwork.Utility;
using EQNetwork.Aspects;

namespace EQNetwork.Objects
{
    public class Session
    {
        public User User { get; set; }

        public Guid? SessionGuid { get; set; }
        public string ExpiredVersion { get; set; }
        public int? InvitationCount { get; set; }
        public int? NotificationCount { get; set; }
        public int? RequestCount { get; set; }
        public List<int> Following { get; set; }
        public List<int> FollowingUser { get; set; }
        public int? MyCollectionCount { get; set; }
        public long? MyStorage { get; set; }

        public Session()
        {
        }

        public override string ToString()
        {
            return SessionGuid + " (" + User.Username + ")";
        }

        public Session(XmlNode root)
        {
            XmlNode child = root.FirstChild;
            while (child != null)
            {
                switch (child.Name.ToLower())
                {
                    case "sessionguid": SessionGuid = new Guid(child.InnerText); break;
                    case "user": User = new User(child); break;
                    case "expiredversion": ExpiredVersion = child.InnerText; break;
                    case "invitationcount": InvitationCount = EQParse.IntOrZero(child.InnerText); break;
                    case "requestcount": RequestCount = EQParse.IntOrZero(child.InnerText); break;
                    case "notificationcount": NotificationCount = EQParse.IntOrZero(child.InnerText); break;
                    case "following": Following = EQParse.IntList(child.InnerText); break;
                    case "followinguser": FollowingUser = EQParse.IntList(child.InnerText); break;
                    case "nycollectioncount": MyCollectionCount = EQParse.IntOrZero(child.InnerText); break;
                    case "mystorage": MyStorage = EQParse.LongOrZero(child.InnerText); break;
                }
                child = child.NextSibling;
            }
        }
    }
}
