import { Controller, Get, UseGuards, Request, ForbiddenException } from '@nestjs/common';
import { DashboardService } from './dashboard.service';
import { AuthGuard } from '@nestjs/passport';

@Controller('dashboard')
@UseGuards(AuthGuard('jwt'))
export class DashboardController {
    constructor(private readonly dashboardService: DashboardService) { }

    @Get('stats')
    getStats(@Request() req) {
        return this.dashboardService.getStats(req.user);
    }

    @Get('my')
    getMyDashboard(@Request() req) {
        return this.dashboardService.getMyDashboard(req.user);
    }

    @Get('manager')
    getManagerDashboard(@Request() req) {
        const allowedRoles = ['ADMIN', 'GENERAL_MANAGER', 'MANAGER'];
        if (!allowedRoles.includes(req.user.role)) {
            throw new ForbiddenException('Access restricted to managers and admins.');
        }
        return this.dashboardService.getManagerDashboard(req.user);
    }
}
