import {
  Controller,
  Get,
  UseGuards,
  HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AdminService } from './admin.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';
import { UserRole } from '../common/enums';

@ApiTags('Admin')
@Controller('admin')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
@ApiBearerAuth()
export class AdminController {
  constructor(private readonly adminService: AdminService) {}

  @Get('stats')
  @ApiOperation({ summary: 'Get platform statistics (admin only)' })
  async getStats() {
    const stats = await this.adminService.getStats();
    return {
      data: stats,
      message: 'Statistics retrieved successfully',
      statusCode: HttpStatus.OK,
    };
  }

  @Get('users/online')
  @ApiOperation({ summary: 'Get online users (admin only)' })
  async getOnlineUsers() {
    const onlineUsers = await this.adminService.getOnlineUsers();
    return {
      data: onlineUsers,
      message: 'Online users retrieved successfully',
      statusCode: HttpStatus.OK,
    };
  }
}
