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

@ApiTags('AI智能分析')
@Controller('ai')
export class AiController {
  constructor(private readonly aiService: AiService) {}

  @Get('analyze/:symbol')
  @ApiOperation({ summary: 'AI智能分析品种' })
  @ApiParam({ name: 'symbol', description: '品种代码' })
  @ApiResponse({ status: 200, description: '分析成功' })
  async analyzeSymbol(@Param('symbol') symbol: string) {
    return this.aiService.analyzeSymbol(symbol);
  }

  @Get('batch-analyze')
  @ApiOperation({ summary: '批量AI分析' })
  @ApiResponse({ status: 200, description: '分析成功' })
  async batchAnalyze(@Query('symbols') symbols: string) {
    const symbolList = symbols.split(',');
    const results = await Promise.all(
      symbolList.map((s) => this.aiService.analyzeSymbol(s.trim())),
    );
    return symbolList.reduce((acc, symbol, index) => {
      acc[symbol] = results[index];
      return acc;
    }, {});
  }
}
