using System;
using System.Net;
using System.ComponentModel;

namespace GeoDashboard
{
    public class InfoValue : BaseObject
    {
        string _key, _name;
        object _value;
        double _percent, _percentMax;

        /// <summary>
        /// Initializes a new instance of a <see cref="InfoValue"/>.
        /// </summary>
        public InfoValue(InfoSource source, string key, string name, object value)
        {
            Source = source;
            Name = name;
            Key = key;
            Value = value;
        }
        /// <summary>
        /// Gets or sets the <see cref="InfoSource"/> that owns this variable.
        /// </summary>
        InfoSource Source { get; set; }
        /// <summary>
        /// Gets or sets the unique key that identifies this variable.
        /// </summary>
        public string Key
        {
            get { return _key; }
            set
            {
                if (value != _key)
                {
                    _key = value;
                    OnPropertyChanged("Key");
                }
            }
        }
        /// <summary>
        /// Gets or sets the name of this variable.
        /// </summary>
        public string Name
        {
            get { return _name; }
            set
            {
                if (value != _name)
                {
                    _name = value;
                    OnPropertyChanged("Name");
                }
            }
        }
        /// <summary>
        /// Gets or sets the current value of this variable.
        /// </summary>
        public object Value
        {
            get 
            {
                if (Source != null && !Source.HasListeners)
                {
                    Source.HasListeners = true;
                }
                return _value; 
            }
            set
            {
                if (value != _value)
                {
                    _value = value;
                    OnPropertyChanged("Value");
                }
            }
        }
        /// <summary>
        /// Gets or sets the current value of this variable as a percentage of all
        /// the variables on a containing list.
        /// </summary>
        public double Percent
        {
            get { return _percent; }
            set
            {
                if (value != _percent)
                {
                    _percent = value;
                    OnPropertyChanged("Percent");
                }
            }
        }
        /// <summary>
        /// Gets or sets the current value of this variable as a percentage of the
        /// highest-valued variable on a containing list.
        /// </summary>
        public double PercentMax
        {
            get { return _percentMax; }
            set
            {
                if (value != _percentMax)
                {
                    _percentMax = value;
                    OnPropertyChanged("PercentMax");
                }
            }
        }
    }
}
