import { Router } from 'express';
import type { Request, Response } from 'express';
import { DashboardController } from '../controllers/dashboard.controller';
import { authenticateToken } from '../middlewares/auth.middleware';
import { asyncHandler } from '../middlewares/errorHandler.middleware';

const router = Router();
const dashboardController = new DashboardController();

/**
 * Dashboard Routes
 * All routes require authentication
 */

// Get KPI summary (all KPI cards)
router.get('/kpis',
  authenticateToken,
  asyncHandler(dashboardController.getKPIs.bind(dashboardController))
);

// Get detailed request statistics
router.get('/stats/requests',
  authenticateToken,
  asyncHandler(dashboardController.getRequestStats.bind(dashboardController))
);

// Get TAT efficiency metrics
router.get('/stats/tat-efficiency',
  authenticateToken,
  asyncHandler(dashboardController.getTATEfficiency.bind(dashboardController))
);

// Get approver load statistics
router.get('/stats/approver-load',
  authenticateToken,
  asyncHandler(dashboardController.getApproverLoad.bind(dashboardController))
);

// Get engagement & quality metrics
router.get('/stats/engagement',
  authenticateToken,
  asyncHandler(dashboardController.getEngagementStats.bind(dashboardController))
);

// Get AI & closure insights
router.get('/stats/ai-insights',
  authenticateToken,
  asyncHandler(dashboardController.getAIInsights.bind(dashboardController))
);

// Get AI Remark Utilization with monthly trends
router.get('/stats/ai-remark-utilization',
  authenticateToken,
  asyncHandler(dashboardController.getAIRemarkUtilization.bind(dashboardController))
);

// Get Approver Performance metrics
router.get('/stats/approver-performance',
  authenticateToken,
  asyncHandler(dashboardController.getApproverPerformance.bind(dashboardController))
);

// Get recent activity feed
router.get('/activity/recent',
  authenticateToken,
  asyncHandler(dashboardController.getRecentActivity.bind(dashboardController))
);

// Get high priority/critical requests
router.get('/requests/critical',
  authenticateToken,
  asyncHandler(dashboardController.getCriticalRequests.bind(dashboardController))
);

// Get upcoming deadlines
router.get('/deadlines/upcoming',
  authenticateToken,
  asyncHandler(dashboardController.getUpcomingDeadlines.bind(dashboardController))
);

// Get department-wise summary
router.get('/stats/by-department',
  authenticateToken,
  asyncHandler(dashboardController.getDepartmentStats.bind(dashboardController))
);

// Get priority distribution
router.get('/stats/priority-distribution',
  authenticateToken,
  asyncHandler(dashboardController.getPriorityDistribution.bind(dashboardController))
);

// Get Request Lifecycle Report
router.get('/reports/lifecycle',
  authenticateToken,
  asyncHandler(dashboardController.getLifecycleReport.bind(dashboardController))
);

// Get enhanced User Activity Log Report
router.get('/reports/activity-log',
  authenticateToken,
  asyncHandler(dashboardController.getActivityLogReport.bind(dashboardController))
);

// Get Workflow Aging Report
router.get('/reports/workflow-aging',
  authenticateToken,
  asyncHandler(dashboardController.getWorkflowAgingReport.bind(dashboardController))
);

// Get departments metadata (for filtering)
router.get('/metadata/departments',
  authenticateToken,
  asyncHandler(dashboardController.getDepartments.bind(dashboardController))
);

// Get single approver stats only (for performance - separate from requests)
router.get('/stats/single-approver',
  authenticateToken,
  asyncHandler(dashboardController.getSingleApproverStats.bind(dashboardController))
);

// Get requests filtered by approver ID (for detailed performance analysis)
router.get('/requests/by-approver',
  authenticateToken,
  asyncHandler(dashboardController.getRequestsByApprover.bind(dashboardController))
);

export default router;

