// <copyright file="FormattingStreamWriter.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

#pragma warning disable SA1309 // Variables should not begin with underscore

namespace Jellyfin.Extensions
{
    using System;
    using System.IO;

    /// <summary>
    /// A custom StreamWriter which supports setting a IFormatProvider.
    /// </summary>
    public class FormattingStreamWriter : StreamWriter
    {
        private readonly IFormatProvider _formatProvider;

        /// <summary>
        /// Initializes a new instance of the <see cref="FormattingStreamWriter"/> class.
        /// </summary>
        /// <param name="stream">The stream to write to.</param>
        /// <param name="formatProvider">The format provider to use.</param>
        public FormattingStreamWriter(Stream stream, IFormatProvider formatProvider)
            : base(stream)
        {
            this._formatProvider = formatProvider;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FormattingStreamWriter"/> class.
        /// </summary>
        /// <param name="path">The complete file path to write to.</param>
        /// <param name="formatProvider">The format provider to use.</param>
        public FormattingStreamWriter(string path, IFormatProvider formatProvider)
            : base(path)
        {
            this._formatProvider = formatProvider;
        }

        /// <inheritdoc />
        public override IFormatProvider FormatProvider
            => this._formatProvider;
    }
}
