using System;

namespace Volpe.Cafe.MarketData
{
    /// <summary>
    /// Defines the compliance information associated with the California and Section 177 (CA+S177) states Zero
    /// Emissions Vehicle (ZEV) requirement.
    /// </summary>
    [Serializable]
    public class ZevCompliance : ICloneable, IAppendable
    {
        /// <summary>Gets or sets the ZEV target.</summary>
        public double Target { get; set; }
        /// <summary>Gets or sets the accumulated ZEV credits.</summary>
        public double Credits { get; set; }

        /// <summary>Gets the ZEV shortfall.</summary>
        public double Shortfall => Math.Max(0, this.Target - this.Credits);

        /// <summary>
        /// Resets all ZEV compliance statistics to zero.
        /// </summary>
        public void Clear()
        {
            this.Target = 0;
            this.Credits = 0;
        }

        /// <summary>
        /// Appends all values from the specified <see cref="ZevCompliance"/> object to this instance.
        /// </summary>
        public void Append(ZevCompliance value)
        {
            this.Target += value.Target;
            this.Credits += value.Credits;
        }

        /// <summary>
        /// Creates a new object that is a copy of the current <see cref="ZevCompliance"/> instance.
        /// </summary>
        /// <returns>A new object that is a copy of this <see cref="ZevCompliance"/>.</returns>
        public ZevCompliance Clone()
        {
            return new ZevCompliance {
                Target = this.Target,
                Credits = this.Credits
            };
        }

        //----- explicit interface implementation -----
        void IAppendable.Append(IAppendable value)
        {
            this.Append((ZevCompliance)value);
        }
        object ICloneable.Clone()
        {
            return this.Clone();
        }

    }
}
