#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

using System;
using System.Linq;

using Volpe.Cafe.Logging;
using Volpe.Cafe.MarketData.Design;
using Volpe.Cafe.ModelSettings;

namespace Volpe.Cafe.DfsSrModels.SalesEstimators
{
    /// <summary>
    /// Provides the base class for sales estimators.
    /// </summary>
    [Serializable]
    public abstract class SalesEstimatorBase : ISalesEstimator
    {
        /// <summary>
        /// Initializes a new instances of the <see cref="SalesEstimatorBase"/> class, using the specified industry
        /// data, modeling settings, and log writer.
        /// </summary>
        /// <param name="data">The product plan industry data used for analysis.</param>
        /// <param name="settings">The modeling settings used for analysis.</param>
        /// <param name="logWriter">The object used for writing log files generated during compliance modeling.</param>
        /// <exception cref="ArgumentNullException">data, settings, or logWriter is null.</exception>
        public SalesEstimatorBase(IIndustry data, ModelingSettings settings, ILogger logWriter)
        {
            ThrowHelper.ThrowIfInvalidArgs(data, settings, logWriter);

            this.Data = data;
            this.Settings = settings;
            this.LogWriter = logWriter;
            this.MinYear = settings.RuntimeSettings.AnalysisStartYear;
            this.MaxYear = settings.RuntimeSettings.AnalysisEndYear;
        }

        public IIndustry Data { get; }
        public ModelingSettings Settings { get; }
        public ILogger LogWriter { get; }

        /// <summary>
        /// Gets the first model year available for compliance modeling.
        /// </summary>
        public int MinYear { get; }
        /// <summary>
        /// Gets the last model year available for compliance modeling.
        /// </summary>
        public int MaxYear { get; }

        public abstract double CalcNewLightDutySales(
            Scenario scen, int iteration, int year, ForecastFleet baseFleet, ForecastFleet scenFleet);

        public abstract double CalcNewHdpuvSales(
            Scenario scen, int iteration, int year, ForecastFleet baseFleet, ForecastFleet scenFleet);

        /// <summary>
        /// Returns the initial (baseline or first year) total light-duty sales using the product plan industry data.
        /// </summary>
        protected double GetBaselineLightDutySales()
        {
            return this.Data.Vehicles.Where(veh => veh.RegClass.IsLD()).Sum(veh => veh.BaselineInfo.Sales);

        }

        /// <summary>
        /// Returns the initial (baseline or first year) total HDPUV sales using the product plan industry data.
        /// </summary>
        protected double GetBaselineHdpuvSales()
        {
            return this.Data.Vehicles.Where(veh => veh.RegClass.IsHDPUV()).Sum(veh => veh.BaselineInfo.Sales);
        }

    }
}
