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

using System;

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

namespace Volpe.Cafe.DfsSrModels.DfsModels
{
    /// <inheritdoc cref="DfsModel.FixedFleetShares"/>
    [Serializable]
    public class FixedFleetShares : DfsModelBase
    {
        /// <summary>
        /// Initializes a new instances of the <see cref="FixedFleetShares"/> class, using the specified industry data,
        /// modeling settings, and log writer.
        /// </summary>
        /// <inheritdoc path="/param"/>
        /// <inheritdoc path="/exception"/>
        public FixedFleetShares(IIndustry data, ModelingSettings settings, ILogger logWriter)
            : base(data, settings, logWriter)
        {
            this.CalcBaselineCarShares();
        }

        private FleetTypeValue _fleetShares;

        private void CalcBaselineCarShares()
        {
            double carSales = 0;
            double truckSales = 0;

            foreach (var veh in this.Data.Vehicles) {
                if (veh.BaselineInfo.RegClass.IsPC()) {
                    carSales += veh.BaselineInfo.Sales;
                }
                else if (veh.BaselineInfo.RegClass.IsLT()) {
                    truckSales += veh.BaselineInfo.Sales;
                }
            }

            double totalLdSales = carSales + truckSales;
            this._fleetShares = new FleetTypeValue(carSales / totalLdSales, truckSales / totalLdSales, 1);
        }

        public override AggregationMode PreferredAggregationMode => AggregationMode.ByBaselineRegClass;
        public override int NumberOfLaggedYears => 0;

        protected override FleetTypeValue CalcNewFleetSharesInternal(Scenario scen, int iteration, int year,
            AnnualValue<ForecastFleet> baseFleet, AnnualValue<ForecastFleet> scenFleet)
        {
            return this._fleetShares;
        }

    }
}
