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 Product : PropertyChangeTracker
    {
        // not writeable
        public int? ProductId { get; private set; }
        public string Active { get; private set; }
        public DateTime? Created { get; private set; }
        public DateTime? Modified { get; private set; }
        public float? SortBy { get; private set; }
        public string Name { get; private set; }
        public string Description { get; private set; }
        public int? ProductTypeId { get; private set; }
        public long? BaseStorage { get; private set; }
        public TimeSpan? Duration { get; private set; }
        public DateTime? ExpirationDate { get; private set; }

        public Product()
        {
        }

        public Product(XmlNode node)
        {
            EQParse.SetPropertiesWithXmlAttributes(this, node);
            ClearPropertyChanges();
        }

        public override string ToString()
        {
            return Name;
        }

        public static List<Product> ParseList(XmlNode root)
        {
            List<Product> list = new List<Product>();
            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name.Equals("ArrayOfProduct", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (XmlNode child in node.ChildNodes)
                        list.Add(new Product(child));
                }
            }
            return list;
        }
    }
}
