using System;
using System.Collections.Generic;
using System.IO;
using Volpe.Cafe.Initializers;

namespace Volpe.Cafe.ModelSettings
{
    /// <summary>
    /// Provides information relating to all available vehicle technologies, containing technology definitions,
    /// attributes, and costs for all vehicle- and engine-technology classes, as well as other cross-technology global
    /// parameters.
    /// </summary>
    [Serializable]
    public sealed class Technologies
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Technologies"/> class.
        /// </summary>
        public Technologies(Dictionary<string, object> values)
        {
            DataObjectInitializer.SetPropertyValues(this, values);
        }


        /// <summary>
        /// Gets the <see cref="TechnologyInfo"/>, containing technology definitions, attributes, and costs, for a
        /// technology with the specified index.
        /// </summary>
        public TechnologyInfo this[int index] => this.TechnologyList[index];

        /// <summary>
        /// Gets the number of defined vehicle technologies.
        /// </summary>
        public int TechnologyCount => (this.TechnologyList == null) ? 0 : this.TechnologyList.Count;

        /// <summary>
        /// Gets a list of vehicle technologies containing technology definitions, attributes, and costs for all
        /// vehicle- and engine-technology classes.
        /// </summary>
        public IReadOnlyList<TechnologyInfo> TechnologyList { get; private set; }

        //----- global parameters -----
        /// <summary>Gets the assumed average glider share for each technology class.</summary>
        public IReadOnlyList<double> GliderShare { get; private set; }


        /// <summary>
        /// Summarizes the information about this <see cref="Technologies"/> instance to the specified
        /// <see cref="TextWriter"/>.
        /// </summary>
        public void WriteSummaryInfo(TextWriter writer)
        {
            if (writer == null) {
                return;
            }

            writer.WriteLine("--- Technologies Analyzed ---");
            if (this.TechnologyList == null || this.TechnologyList.Count == 0) {
                writer.WriteLine("  No technology data available.");
            }
            else {
                foreach (TechnologyInfo tech in this.TechnologyList) {
                    writer.WriteLine($"  {tech.Index} - {tech.Name}");
                }
            }
            writer.WriteLine();
        }

    }
}
