import { Controller, Post, Body, Get, HttpCode, HttpStatus, ValidationPipe } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { WaitlistService } from './waitlist.service';
import { CreateWaitlistDto } from './dto/create-waitlist.dto';
import { Public } from '../../common/decorators/public.decorator';

@ApiTags('waitlist')
@Controller('waitlist')
export class WaitlistController {
  constructor(private readonly waitlistService: WaitlistService) {}

  @Public()
  @Post()
  @HttpCode(HttpStatus.CREATED)
  @ApiOperation({ summary: '加入等待名单' })
  @ApiResponse({ status: 201, description: '成功加入' })
  async create(@Body(new ValidationPipe({ transform: true })) dto: CreateWaitlistDto) {
    const entry = await this.waitlistService.create(dto);
    return { success: true, message: '已成功加入等待名单', data: { id: entry.id, email: entry.email } };
  }

  @Get()
  @ApiOperation({ summary: '获取等待名单' })
  async findAll() {
    return this.waitlistService.findAll();
  }

  @Get('stats')
  @ApiOperation({ summary: '获取报名统计' })
  async getStats() {
    return this.waitlistService.getStats();
  }
}
