import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard, Roles, RolesGuard } from '@genex/common';
import { UserRole } from '@genex/common';
import { AdminDashboardService } from '../../../application/services/admin-dashboard.service';

@ApiTags('Admin - Dashboard')
@Controller('admin/dashboard')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
@ApiBearerAuth()
export class AdminDashboardController {
  constructor(private readonly dashboardService: AdminDashboardService) {}

  @Get('stats')
  @ApiOperation({ summary: 'Get dashboard overview stats' })
  async getStats() {
    const data = await this.dashboardService.getStats();
    return { code: 0, data };
  }

  @Get('realtime-trades')
  @ApiOperation({ summary: 'Get recent transactions (paginated)' })
  async getRealtimeTrades(
    @Query('page') page = 1,
    @Query('limit') limit = 20,
  ) {
    const data = await this.dashboardService.getRealtimeTrades(+page, +limit);
    return { code: 0, data };
  }

  @Get('system-health')
  @ApiOperation({ summary: 'Get system health status of all services' })
  async getSystemHealth() {
    const data = await this.dashboardService.getSystemHealth();
    return { code: 0, data };
  }
}
