using System;

namespace Volpe.Cafe.EffectsData
{
    /// <summary>
    /// Represents an object that stores modeling data based on various discount rates.
    /// </summary>
    [Serializable]
    public class ValueByDiscRate : IAppendable
    {
        /// <summary>
        /// Gets the modeling data value associated with inputs pre-discounted at 3%.
        /// </summary>
        public double DR3 { get; set; }
        /// <summary>
        /// Gets the modeling data value associated with inputs pre-discounted at 7%.
        /// </summary>
        public double DR7 { get; set; }

        /// <summary>
        /// Gets the modeling data value based on the given <paramref name="discRate"/>.
        /// </summary>
        /// <param name="discRate">
        ///     The approximate discount rate to use for retrieving modeling data value associated with pre-discounted
        ///     inputs. If the discount rate is >=5%, the modeling data value associated with inputs pre-discounted at
        ///     7% will be used; otherwise, the modeling data value associated with inputs pre-discounted at 3% will be
        ///     returned.
        /// </param>
        public double this[double discRate] => (discRate >= 0.05) ? this.DR7 : this.DR3;

        /// <summary>
        /// Resets all values to zero.
        /// </summary>
        public void Clear()
        {
            this.DR3 = 0;
            this.DR7 = 0;
        }

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

        //----- explicit interface implementation -----
        void IAppendable.Append(IAppendable value)
        {
            this.Append((ValueByDiscRate)value);
        }

    }
}
