using ReportGeneration.Abstract;
using ReportGeneration.Interface;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace ReportGeneration.Generators;

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;
  }
}
