using System;
using System.IO;

using Volpe.Cafe.IO.CSV;
using Volpe.Cafe.IO.DSV;
using Volpe.Cafe.ModelSettings;

namespace Volpe.Cafe.Reporting
{
    /// <summary>
    /// Provides the class that supports generating of the various modeling report files.
    /// </summary>
    [Serializable]
    public class ReportFileWriter : CsvWriter
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ReportFileWriter"/> class for the specified file, using the
        /// default encoding and buffer size. If the file exists, it will be appended to if <paramref name="headers"/>
        /// is <c>null</c>; otherwise, it will be overwritten. If the file does not exist, this constructor creates a
        /// new file. When a new file is created, the specified <paramref name="headers"/> will be written to the file.
        /// When a file is opened in append mode, the headers will be read from the existing file.
        /// </summary>
        /// <param name="path">The complete file path to write to.</param>
        /// <param name="headers">
        ///     An array of column headers to write to the report file, or null, if appending an existing file.
        /// </param>
        /// <exception cref="ArgumentNullException">headers array is null and file is not being appended.</exception>
        /// <exception cref="ArgumentException">headers array is empty and file is not being appended.</exception>
        /// <inheritdoc cref="StreamWriter(string, bool)" path="/exception"/>
        public ReportFileWriter(string path, string[] headers)
            : base(path, headers, DsvFile.DefaultEscapeChar, ReportFile.NewLine) { }

        /// <summary>
        /// Creates a data generator that is compatible with this <see cref="ReportFileWriter"/> and may be used for
        /// generating rows of data to write to the report.
        /// </summary>
        /// <param name="scen">The compliance scenario being analyzed.</param>
        /// <param name="data">The modeling and effects data to report on.</param>
        /// <param name="settings">The modeling settings used for analysis.</param>
        /// <returns>A <see cref="ReportDataGenerator"/> object to use for generating rows of data.</returns>
        /// <remarks>
        /// By default, this method returns <c>null</c>, signifying that no data generator is available. In such a
        /// case, consumers of this class will be responsible for providing their own data values to pass to the
        /// <see cref="DsvWriter.WriteValues"/> method. Subclasses may also override this method to define a custom
        /// data generator that is suitable for a particular modeling report.
        /// </remarks>
        public virtual ReportDataGenerator GetDataGenerator(
            Scenario scen, ReportingData data, ModelingSettings settings)
        {
            return null;
        }

    }
}
