#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)

using System;
using System.IO;

namespace Volpe.Cafe.Reporting.ModelingReports
{
    /// <summary>
    /// Provides the base class for all explicitly defined modeling reports.
    /// </summary>
    [Serializable]
    public abstract class ModelingReport : ReportFileWriter
    {
        /// <summary>
        /// Initializes a new instance of a modeling report for the specified file, using the default encoding and
        /// buffer size. If the file exists, it can be either overwritten or appended to. If the file does not exist,
        /// this constructor creates a new file. When a new file is created, a report-specific headers line will be
        /// written to the file.
        /// </summary>
        /// <param name="path">The complete file path to write to.</param>
        /// <param name="append">
        ///     Specifies whether data is to be appended to the file. If the file exists and append is <c>false</c>,
        ///     the file is overwritten. If the file exists and append is <c>true</c>, the data is appended to the
        ///     file. Otherwise, a new file is created.
        /// </param>
        /// <inheritdoc cref="StreamWriter(string, bool)" path="/exception"/>
        private protected ModelingReport(string path, bool append, Func<string[]> getHeaders)
            : base(path, CanAppend(path, append) ? null : getHeaders())
        {
            if (getHeaders is null) {
                throw new ArgumentNullException(nameof(getHeaders));
            }
        }

        private static bool CanAppend(string path, bool append)
        {
            return append && File.Exists(path);
        }

    }
}
