import { Router, Request, Response, NextFunction } from 'express';
import { volunteerDashboardService } from './volunteer-dashboard.service';
import { authenticate } from '../../middleware/auth.middleware';
import { AppError } from '../../middleware/error-handler';

const router = Router();

router.get(
  '/dashboard',
  authenticate,
  async (req: Request, res: Response, next: NextFunction) => {
    try {
      const data = await volunteerDashboardService.getDashboard(req.user!.id);
      if (!data) throw new AppError(404, 'User not found', 'USER_NOT_FOUND');
      res.json(data);
    } catch (err) {
      next(err);
    }
  },
);

export { router as volunteerDashboardRouter };
