using System;
using System.Collections.Generic;
using Volpe.Cafe.MarketData;

namespace Volpe.Cafe.TechAnalysis
{
    /// <summary>
    /// Defines a technology solution associated with application of pending technologies on one or more vehicle models
    /// during a specific model year.
    /// </summary>
    [Serializable]
    public class TechSolution
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TechSolution"/> class.
        /// </summary>
        /// <param name="year">The model year associated with this instance.</param>
        public TechSolution(int year)
        {
            this.ModelYear = year;
            this.ApplicationYears = new List<int>();
            this.TechImpacts = new List<TechImpact>();
            this.TestVehicles = new List<TestVehicle>();
        }

        /// <summary>
        /// Gets or sets the model year associated with this <see cref="TechSolution"/> instance.
        /// </summary>
        public int ModelYear { get; set; }

        /// <summary>
        /// Gets the model years representing the years of initial application of pending technologies on each of the
        /// affected vehicle models.
        /// </summary>
        /// <remarks>
        /// The application year for any individual vehicle model may not necessarily be the same as the
        /// <see cref="ModelYear"/> for which the technology solution is computed. In the case of a multiyear solution,
        /// the <see cref="ModelYear"/> property represents the year affected by the technology solution, while the
        /// <see cref="ApplicationYears"/> of each vehicle correspond to the earliest availability of the pending
        /// technologies on that vehicle. Typically, this is the redesign or refresh year of the affected vehicles.
        /// </remarks>
        public List<int> ApplicationYears { get; private set; }
        /// <summary>
        /// Gets the accumulated impacts arising from application of pending technologies on each of the vehicle models
        /// during a specific <see cref="ModelYear"/>.
        /// </summary>
        public List<TechImpact> TechImpacts { get; private set; }
        /// <summary>
        /// Gets one or more test vehicles representing the vehicle models affected by application of pending
        /// technologies during a specific <see cref="ModelYear"/>.
        /// </summary>
        public List<TestVehicle> TestVehicles { get; private set; }

        /// <summary>
        /// Gets or sets the compliance statistics based on the current state of the affected vehicle models, before
        /// application of pending technologies.
        /// </summary>
        public ComplianceStatistics CurrentStats { get; set; }
        /// <summary>
        /// Gets or sets the compliance statistics based on the new state of the affected vehicle models, after
        /// application of pending technologies.
        /// </summary>
        public ComplianceStatistics NewStats { get; set; }

        /// <summary>
        /// Refreshes this technology solution for a new test.
        /// </summary>
        /// <param name="year">The model year associated with this instance.</param>
        public void Refresh(int year)
        {
            this.ModelYear = year;
            this.ApplicationYears.Clear();
            this.TechImpacts.Clear();
            this.TestVehicles.Clear();
        }

        /// <summary>
        /// Updates the technology solution, with the specified variables, for a single affected vehicle model.
        /// </summary>
        /// <param name="applicationYear">
        ///     The year of initial application of pending technologies on an affected vehicle model.
        /// </param>
        /// <param name="techImpact">
        ///     The accumulated impact arising from application of pending technologies on an affected vehicle model
        ///     during a specific <see cref="ModelYear"/>.
        /// </param>
        /// <param name="testVeh">
        ///     A test vehicle representing a vehicle model affected by application of pending technologies during a
        ///     specific <see cref="ModelYear"/>.
        /// </param>
        public void Update(int applicationYear, TechImpact techImpact, TestVehicle testVeh)
        {
            this.ApplicationYears.Add(applicationYear);
            this.TechImpacts.Add(techImpact);
            this.TestVehicles.Add(testVeh);
        }

    }
}
