import express from 'express';
import { ReportingService } from '../../services/klaviyo/reporting.service.js';
import { TimeManager } from '../../../shared/business-time/index.js';

export function createReportingRouter(apiKey, apiRevision, redis) {
  const router = express.Router();
  const reportingService = new ReportingService(apiKey, apiRevision, redis);
  const timeManager = new TimeManager();

  // Get campaign reports by time range
  router.get('/campaigns/:timeRange', async (req, res) => {
    try {
      const { timeRange } = req.params;
      const { channel } = req.query;
      
      const reports = await reportingService.getCampaignReports({
        timeRange,
        channel
      });

      res.json(reports);
    } catch (error) {
      console.error('[ReportingRoutes] Error fetching campaign reports:', error);
      res.status(500).json({ error: error.message });
    }
  });

  return router;
} 