import {
  Body,
  Controller,
  HttpCode,
  HttpStatus,
  Post,
  UseGuards,
} from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Throttle } from '@nestjs/throttler';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import type { PublicUser } from '../user/user.service';
import { AiService, type ChecklistSuggestionGroup } from './ai.service';
import { SuggestChecklistDto } from './dto/suggest-checklist.dto';

// AI 보조 — 업무 작성 시 할 일(체크리스트) 추천
@ApiTags('AI')
@Controller('ai')
@UseGuards(JwtAuthGuard)
export class AiSuggestController {
  constructor(private readonly aiService: AiService) {}

  @Post('suggest-checklist')
  @HttpCode(HttpStatus.OK)
  @Throttle({ default: { limit: 1000, ttl: 60_000 } })
  @ApiOperation({ summary: '할 일(체크리스트) 추천 — 프로젝트·업무 기반' })
  @ApiResponse({ status: 200, description: '카테고리별 추천 항목' })
  @ApiResponse({ status: 404, description: '프로젝트 없음 (RES_001)' })
  suggestChecklist(
    @CurrentUser() user: PublicUser,
    @Body() dto: SuggestChecklistDto,
  ): Promise<{ groups: ChecklistSuggestionGroup[] }> {
    return this.aiService.suggestChecklist(user.id, {
      projectId: dto.projectId,
      title: dto.title,
      content: dto.content,
    });
  }
}
