import {
  Controller,
  Get,
  Logger,
  Req,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
import { DashboardService } from './dashboard.service';

@ApiTags('dashboard')
@ApiBearerAuth()
@Controller('dashboard')
export class DashboardController {
  private readonly logger = new Logger(DashboardController.name);

  constructor(private readonly dashboardService: DashboardService) {}

  /**
   * Dashboard ana istatistikleri — kullanıcı bazlı.
   */
  @Get('stats')
  @ApiOperation({ summary: 'Dashboard istatistiklerini getir' })
  @ApiResponse({ status: 200, description: 'Dashboard istatistikleri' })
  async getStats(@Req() req: any) {
    const userId = req.user?.id || req.user?.sub;
    this.logger.debug(`Dashboard stats istendi: ${userId}`);
    return this.dashboardService.getStats(userId);
  }

  /**
   * Video üretim kuyruğu durumu.
   */
  @Get('queue-status')
  @ApiOperation({ summary: 'Kuyruk durum bilgisi' })
  @ApiResponse({ status: 200, description: 'Kuyruk ve WebSocket durumu' })
  async getQueueStatus() {
    return this.dashboardService.getQueueStatus();
  }

  /**
   * Bu ayki video üretim chart verisi (gün bazlı).
   */
  @Get('chart')
  @ApiOperation({ summary: 'Aylık video üretim chart verisi' })
  @ApiResponse({ status: 200, description: 'Gün bazlı üretim verileri' })
  async getMonthlyChart(@Req() req: any) {
    const userId = req.user?.id || req.user?.sub;
    return this.dashboardService.getMonthlyChart(userId);
  }
}
