import { Injectable } from '@nestjs/common';
import { ReportData } from './report.service';

/**
 * Produces the short paragraph shown at the top of the email and PDF.
 *
 * This is a safe, dependency-free template version so the module runs out of
 * the box. If you already have an AI-backed implementation (e.g. an OpenAI /
 * Anthropic call), keep yours — only the method signature
 * `summarize(report): Promise<string>` matters to the rest of the pipeline.
 */
@Injectable()
export class AiSummaryService {
  async summarize(report: ReportData): Promise<string> {
    if (report.total === 0) {
      return `No certificates are due for ${report.monthName} ${report.year} in the selected category.`;
    }

    const parts = report.buckets
      .filter((b) => b.count > 0)
      .map((b) => `${b.count} ${b.label}`)
      .join(', ');

    return (
      `For ${report.monthName} ${report.year}, ${report.total} certificate(s) ` +
      `are due across the selected categories — ${parts}. ` +
      `The full breakdown is attached as Excel and PDF.`
    );
  }
}