using System;
using System.Collections.Generic;
using System.Linq;
using Volpe.Cafe.MarketData.Design;
using Volpe.Cafe.ModelSettings;

namespace Volpe.Cafe.Reporting.Generators
{
    /// <summary>
    /// Defines an enumerable object used for generating rows of data for a transmissions report.
    /// </summary>
    [Serializable]
    public class TransmissionsReportDataGenerator : ComponentReportDataGeneratorBase<ITransmission>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TransmissionsReportDataGenerator"/> class, for the specified
        /// scenario and reporting data.
        /// </summary>
        /// <inheritdoc cref="ReportDataGenerator(Scenario, ReportingData, ModelingSettings)" path="/param"/>
        public TransmissionsReportDataGenerator(Scenario scen, ReportingData data, ModelingSettings settings)
            : base(scen, data, settings) { }

        /// <inheritdoc/>
        protected override IReadOnlyList<ITransmission> GetComponentList(IManufacturer mfr)
        {
            return mfr.Transmissions;
        }

        /// <inheritdoc/>
        protected override string GetComponentTypeString(ITransmission component, List<IVehicleRevision> vehs)
        {
            var trnTypes = vehs.ConvertAll(vehRevision => $"{{{vehRevision.GetVehicleTransmissionType()}}}")
                               .Distinct().ToArray();

            return (trnTypes.Length == 1)
                ? trnTypes[0].Substring(1, trnTypes[0].Length - 2)
                : string.Join(", ", trnTypes);
        }

        /// <inheritdoc/>
        protected override IOEMComponentRevision GetComponentRevision(ITransmission component, IVehicle veh, int year)
        {
            return (component.Code == veh.GetRevision(year).TransmissionCode)
                ? veh.GetTransmissionRevision(year)
                : null;
        }

    }
}
