import { Controller, Get, Middleware } from '@overnightjs/core';
import { Request, Response } from 'express';
import { auth, AuthRequest } from '../middleware/auth';
import Doctor from '../models/Doctor';
import DashboardService from '../services/DashboardService';

@Controller('api/dashboard')
export class DashboardController {

    @Get('stats')
    @Middleware(auth)
    async getStats(req: Request, res: Response) {
        try {
            const userId = (req as AuthRequest).user.userId;
            const stats = await DashboardService.getStats(userId);
            res.status(200).json({
                success: true,
                data: stats
            });
        } catch (error: any) {
            console.error('Error fetching dashboard stats:', error);
            res.status(500).json({ success: false, error: error.message });
        }
    }

    @Get('test-doctors')
    async testDoctors(req: Request, res: Response) {
        try {
            const count = await Doctor.countDocuments();
            const allDoctors = await Doctor.find().limit(5);
            res.json({
                success: true,
                totalCount: count,
                firstFive: allDoctors
            });
        } catch (error: any) {
            res.status(500).json({ success: false, error: error.message });
        }
    }
}
