import { Controller, Get, Param, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiParam, ApiQuery, ApiResponse } from '@nestjs/swagger';
import { EventsService } from './events.service';

@ApiTags('热点事件')
@Controller('events')
export class EventsController {
  constructor(private readonly eventsService: EventsService) {}

  @Get()
  @ApiOperation({ summary: '获取热点事件列表' })
  @ApiQuery({ name: 'impact', required: false, enum: ['bullish', 'bearish', 'neutral'] })
  @ApiQuery({ name: 'startDate', required: false })
  @ApiQuery({ name: 'endDate', required: false })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'size', required: false, type: Number })
  @ApiResponse({ status: 200, description: '获取成功' })
  async getEvents(
    @Query('impact') impact?: string,
    @Query('startDate') startDate?: string,
    @Query('endDate') endDate?: string,
    @Query('page') page = '1',
    @Query('size') size = '20',
  ) {
    return this.eventsService.getEvents(
      impact,
      startDate ? new Date(startDate) : undefined,
      endDate ? new Date(endDate) : undefined,
      parseInt(page, 10),
      parseInt(size, 10),
    );
  }

  @Get(':id')
  @ApiOperation({ summary: '获取事件详情' })
  @ApiParam({ name: 'id', description: '事件ID' })
  @ApiResponse({ status: 200, description: '获取成功' })
  @ApiResponse({ status: 404, description: '事件不存在' })
  async getEventById(@Param('id') id: string) {
    return this.eventsService.getEventById(id);
  }
}
