using System;
using System.Linq;

namespace Volpe.Cafe.EffectsData
{
    /// <summary>
    /// Provides aggregate and annual modeling effects and costs data for a single model year.
    /// </summary>
    [Serializable]
    public sealed class ModelingEffects
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ModelingEffects"/> class.
        /// </summary>
        /// <param name="modelYear">The model year for which the effects data are calculated.</param>
        /// <param name="socialDR">The discount rates at which the owner and societal costs are discounted.</param>
        /// <param name="consumerDR">The discount rates at which the consumer costs are discounted.</param>
        public ModelingEffects(int modelYear, double[] socialDR, double[] consumerDR)
        {
            this.ModelYear = modelYear;
            this.AggregateEffects = new ModelingEffectsItem(socialDR, consumerDR, false);
            this.AnnualEffects = Enumerable.Range(0, Globals.CY)
                                           .Select(_ => new ModelingEffectsItem(socialDR, consumerDR, true))
                                           .ToArray();
        }

        /// <summary>
        /// Gets the model year for which the effects data are calculated.
        /// </summary>
        public int ModelYear { get; }

        /// <summary>
        /// Gets the aggregate modeling effects data for a single model year, accumulated from all vehicle ages.
        /// </summary>
        public ModelingEffectsItem AggregateEffects { get; private set; }

        /// <summary>
        /// Gets the modeling effects data for a single model year, disaggregated by vehicle age.
        /// </summary>
        public ModelingEffectsItem[] AnnualEffects { get; private set; }

        /// <summary>
        /// Aggregates annual effects. The general effects, discount rates, and payback periods are not aggregated.
        /// </summary>
        public void AggregateAnnualEffects()
        {
            foreach (var annualEff in this.AnnualEffects) {
                this.AggregateEffects.Append(annualEff);
            }
        }

    }
}
