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

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

namespace Volpe.Cafe.EffectsModels
{
    /// <summary>
    /// Provides a wrapper around historic vehicle data for a representative historic vehicle, for use during effects
    /// modeling.
    /// </summary>
    public class HistoricEffectsVehicle : IEffectsVehicle
    {
        #region <<< Constructors >>>

        /// <summary>
        /// Initializes a new instance of the <see cref="HistoricEffectsVehicle"/> class, using the specified
        /// regulatory class and vehicle style, and for a given model year.
        /// <br/><br/>
        /// A subset of the historic fleet data, matching the given vehicle style and model year, will be used to
        /// obtain the underlying data for initializing this instance.
        /// </summary>
        /// <param name="regClass">The regulatory class to use for initializing this instance.</param>
        /// <param name="vehStyle">The vehicle style to use for initializing this instance.</param>
        /// <param name="year">
        ///     The model year representing the vintage of the representative historic vehicle whose data to use for
        ///     initializing this instance.
        /// </param>
        /// <param name="settings">The modeling settings used for analysis.</param>
        public HistoricEffectsVehicle(RegulatoryClass regClass,
                                      VehicleStyle vehStyle,
                                      int year,
                                      ModelingSettings settings)
        {
            HistoricFleetDataItem hfd = settings.Parameters.HistoricFleetData.GetHistoricFleetData(vehStyle, year);

            this.Code = (int)regClass * 1000 + (int)vehStyle;
            this.ManufacturerName = "IndustryHistoric";

            this.RevisionYear = year;

            this.FuelEconomy = Effects.ConvertToRatedFE(hfd.OnRoadFE, vehStyle, settings);
            this.RatedFE = Effects.ConvertToRatedFE(hfd.OnRoadFE, vehStyle, settings);
            this.OnRoadFE = hfd.OnRoadFE;
            this.FuelShare = hfd.FuelShare;
            this.Sales = hfd.InitialProduction;
            this.Msrp = hfd.TransactionPrice;
            this.RegClass = regClass;
            this.VehicleClass = vehStyle.ToVehicleClass();
            this.Style = vehStyle;
            this.CurbWeight = hfd.CurbWeight;
            this.FuelCapacity = hfd.FuelCapacity;

            this.FleetShare = regClass.IsPC() ? hfd.PCShare
                            : regClass.IsLT() ? 1 - hfd.PCShare
                            : 1;
        }

        #endregion

        #region <<< Properties >>>

        //----- general vehicle info -----
        public int Code { get; }
        public string ManufacturerName { get; }
        public int RevisionYear { get; }

        //----- fuel-economy values -----
        public FuelValue FuelEconomy { get; }
        public FuelValue FuelShare { get; }
        public FuelType FuelType => this.FuelShare.FuelType;

        //----- sales/msrp -----
        public double Sales { get; }
        public double Msrp { get; }

        //----- regulatory classification -----
        public RegulatoryClass RegClass { get; }
        public VehicleClass VehicleClass { get; }

        //----- vehicle characteristics -----
        public VehicleStyle Style { get; }

        public double CurbWeight { get; }
        public double FuelCapacity { get; }

        //----- IVehicleInfo -----
        public FuelValue RatedFE { get; }
        public FuelValue OnRoadFE { get; }

        public FuelValue InitFuelEconomy => this.FuelEconomy;
        public FuelValue InitRatedFE => this.RatedFE;
        public FuelValue InitOnRoadFE => this.OnRoadFE;
        public FuelValue InitFuelShare => this.FuelShare;
        public FuelType InitFuelType => this.InitFuelShare.FuelType;
        public double InitCurbWeight => this.CurbWeight;

        public double FleetShare { get; }
        public bool IsHistoric => true;

        #endregion

        #region <<< Explicitly Implemented Properties >>>

        //----- general vehicle info -----
        ModelYearKey IOEMProductInfo.RefreshYears => ModelYearKey.Empty;
        ModelYearKey IOEMProductInfo.RedesignYears => ModelYearKey.Empty;

        string IVehicleInfo.Brand => string.Empty;
        string IVehicleInfo.Model => string.Empty;
        string IVehicleInfo.Nameplate => string.Empty;

        int IVehicleInfo.PlatformCode => 0;
        int IVehicleInfo.EngineCode => 0;
        int IVehicleInfo.TransmissionCode => 0;

        //----- regulatory classification -----
        SafetyClass IVehicleInfo.SafetyClass => SafetyClass.None;
        TechnologyClass IVehicleInfo.TechnologyClass => TechnologyClass.None;
        EngineTechnologyClass IVehicleInfo.EngineTechnologyClass => EngineTechnologyClass.None;

        bool IVehicleInfo.IsZevCandidate => false;
        int? IVehicleInfo.ZEVCandidate => null;
        int IVehicleInfo.ZevApplicationYear => 0;
        int IVehicleInfo.ZevReferenceVehicleCode => 0;
        bool IVehicleInfo.CARBAgreement => false;

        //----- vehicle characteristics -----
        Origin IVehicleInfo.Origin => Origin.Domestic;
        VehicleFrame IVehicleInfo.Structure => VehicleFrame.None;
        DriveType IVehicleInfo.Drive => DriveType.None;

        double IVehicleInfo.Footprint => 0;
        double IVehicleInfo.CurbWeightMR0 => 0;
        double IVehicleInfo.GVWR => 0; 
        double IVehicleInfo.GCWR => 0;

        //----- vehicle powertrain -----
        HEVType IVehicleInfo.HevType => HEVType.All;
        TechKey128 IOEMProductInfo.TechKey => TechKey128.Empty;

        #endregion
    }
}
