require 'fileutils'
require 'rubyXL'
require 'rubyXL/convenience_methods'
require_relative 'report/tsv'
require_relative 'report/excel'

class Report
  def self.run(filename, rows, batch_id, output_location, output_type)
    report = Report.new(filename, rows, batch_id, output_location, output_type)
    report.execute
  end

  def initialize(filename, rows, batch_id, output_location, output_type)
    @filename = filename
    @output_location = output_location
    @data = rows.reverse
    @batch_id = batch_id
    @output_type = output_type
  end

  def execute
    FileUtils.mkdir_p @output_location

    case @output_type
    when 'tsv'
      TSV.execute(@data, @filename, @output_location, @batch_id)
    when 'excel'
      Excel.execute(@data, @filename, @output_location, @batch_id)
    else
      "Unrecognized output type specified. No output file will be written"
    end
  end
end

