import { Request, Response } from 'express';
import { dealerDashboardService } from '../services/dealerDashboard.service';
import logger from '@utils/logger';

export class DealerDashboardController {
  /**
   * Get dealer dashboard KPIs and category data
   * GET /api/v1/dealer-claims/dashboard
   */
  async getDashboard(req: Request, res: Response): Promise<void> {
    try {
      const userId = (req as any).user?.userId;
      const userEmail = (req as any).user?.email;
      const dateRange = req.query.dateRange as string | undefined;
      const startDate = req.query.startDate as string | undefined;
      const endDate = req.query.endDate as string | undefined;

      const result = await dealerDashboardService.getDashboardKPIs(
        userEmail,
        userId,
        dateRange,
        startDate,
        endDate
      );

      res.json({
        success: true,
        data: result
      });
    } catch (error) {
      logger.error('[DealerDashboard] Error fetching dashboard:', error);
      res.status(500).json({
        success: false,
        error: 'Failed to fetch dealer dashboard data'
      });
    }
  }
}

