import type { FastifyRequest, FastifyReply } from 'fastify';
import { getOrderReport, getProductionReport, getDispatchReport } from '../services/report.service.js';

export async function getReportHandler(request: FastifyRequest, _reply: FastifyReply) {
  const { category, reportId } = request.params as { category: string; reportId: string };
  const query = request.query as { dateFrom?: string; dateTo?: string; clientId?: string; employeeId?: string; orderNo?: string; status?: string; stage?: string };

  if (category === 'orders') {
    return getOrderReport(reportId, query);
  }
  if (category === 'production') {
    return getProductionReport(reportId, query);
  }
  if (category === 'dispatch') {
    return getDispatchReport(reportId, query);
  }

  return { columns: [], rows: [], totals: {} };
}
