import { TerminalReporter } from './terminal';
import { JsonReporter } from './json';
import { MarkdownReporter } from './markdown';
import { HtmlReporter } from './html';
import { HtmlCompactReporter } from './html-compact';
import { TextReporter } from './text';
import type { CoverageReport, ReporterType } from '../types';

export class ReporterManager {
  private reporters = {
    terminal: new TerminalReporter(),
    json: new JsonReporter(),
    markdown: new MarkdownReporter(),
    html: new HtmlCompactReporter(),  // Use compact HTML by default
    'html-full': new HtmlReporter(),   // Keep full HTML as option
    text: new TextReporter(),
  };

  async report(coverage: CoverageReport, reporters: ReporterType[], outputDir: string): Promise<void> {
    for (const reporterType of reporters) {
      try {
        const reporter = this.reporters[reporterType];
        if (!reporter) {
          console.warn(`Unknown reporter type: ${reporterType}`);
          continue;
        }

        if (reporterType === 'terminal') {
          reporter.report(coverage);
        } else {
          reporter.report(coverage, outputDir);
        }
      } catch (error) {
        console.error(`Error running ${reporterType} reporter:`, error);
      }
    }
  }
}