namespace AvevaMemberListWindow
{
    using System;

    /// <summary>
    /// Элемент таблицы
    /// </summary>
    public class MemberListItem
    {
        private string type;
        private string spRef;
        private string description;
        private double weight;
        private double count;

        /// <summary>
        /// Конструктор
        /// </summary>
        /// <param name="type">Тип</param>
        /// <param name="spRef">Название стандарта</param>
        /// <param name="weight">Вес одной единицы</param>
        /// <param name="count">Количество</param>
        /// <param name="description">Детальное описание</param>
        public MemberListItem(string type, string spRef, double weight, double count, string description)
        {
            this.type = type;
            this.spRef = spRef;
            this.weight = weight;
            this.count = count;
            this.description = description;
        }

        /// <summary>
        /// Сложение двух одинаковых элементов
        /// </summary>
        /// <param name="item">Элемент для сложения</param>
        /// <returns>True в случае удачного сложения элементов</returns>
        public bool AddItem(MemberListItem item)
        {
            if (!item.Type.Equals(this.type) || 
                !item.SpRef.Equals(this.spRef) || 
                !item.Weight.Equals(this.weight))
                return false;

            this.count += item.Count;

            return true;
        }

        /// <summary>
        /// Тип
        /// </summary>
        public string Type
        {
            get { return this.type; }
            set { this.type = value; }
        }

        /// <summary>
        /// Название стандарта
        /// </summary>
        public string SpRef
        {
            get { return this.spRef; }
            set { this.spRef = value; }
        }

        /// <summary>
        /// Вес 1 единицы
        /// </summary>
        public double Weight
        {
            get { return this.weight; }
            set { this.weight = value; }
        }

        /// <summary>
        /// Количество
        /// </summary>
        public double Count
        {
            get { return this.count; }
            set { this.count = value; }
        }

        /// <summary>
        /// Суммарный вес (округлено до 3го знака)
        /// </summary>
        public double WeightSum
        {
            get { return Math.Round(this.count * this.weight, 3); }
        }

        /// <summary>
        /// Детальное описание
        /// </summary>
        public string Description
        {
            get { return this.description; }
            set { this.description = value; }
        }

        /// <summary>
        /// Вовзращает свойства элемента в виде массива
        /// </summary>
        public string[] ToArray()
        {
            return new string[] { this.Type, this.SpRef, this.Weight.ToString(), this.Count.ToString(), this.WeightSum.ToString(), this.Description };
        }
    }
}
