# frozen_string_literal: true

module Reportgen
  # The new-style CSV writer: given a resolved header list and rows, writes
  # a clean CSV string. This is the intended replacement for the inline
  # writing code still living in Exporter#export, but nothing calls it yet.
  class ExportWriter
    def write(headers:, rows:)
      lines = [headers.join(",")]
      rows.each do |row|
        lines << headers.map { |header| row.fetch(header, "").to_s }.join(",")
      end
      lines.join("\n")
    end
  end
end
