using ReportGenerator.Generator.Abstract;
using ReportGenerator.Generator.Interface;
using System.Text;

namespace ReportGenerator.Generator.Generator;

internal class MarkdownTableGenerator : TableGeneratorBase
{
  private const string ColumnSeparator = " | ";

  /// <inheritdoc />
  public MarkdownTableGenerator(int columns)
    : base(columns) { }

  /// <inheritdoc />
  public MarkdownTableGenerator(int columns, Stream stream)
    : base(columns, stream) { }

  /// <inheritdoc />
  public MarkdownTableGenerator(int columns, Stream stream, Encoding encoding)
    : base(columns, stream, encoding) { }

  /// <inheritdoc />
  public override ITableGenerator AppendHeader(IEnumerable<string> row) =>
    this
      .AppendRow(row)
      .AppendRow("---");

  /// <inheritdoc />
  public override ITableGenerator AppendRow(IEnumerable<string> row)
  {
    Writer.WriteLine(ColumnSeparator + string.Join(" | ", row) + ColumnSeparator);
    return this;
  }
}
