import { Controller, Get, Post, Param, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { ReviewService } from './review.service';
import { SubmitReviewDto } from './dto/submit-review.dto';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import type { UserPayload } from '../../common/types';

@ApiTags('review')
@Controller('reviews')
export class ReviewController {
  constructor(private readonly reviewService: ReviewService) {}

  @Get('due')
  @ApiOperation({ summary: '获取到期复习卡片' })
  @ApiResponse({ status: 200, description: '到期复习卡片列表' })
  async getDue(@CurrentUser() user: UserPayload) {
    return this.reviewService.getDueCards(String(user?.id || 'anonymous'));
  }

  @Post(':id/submit')
  @HttpCode(HttpStatus.CREATED)
  @ApiOperation({ summary: '提交复习结果' })
  @ApiResponse({ status: 201, description: '提交成功' })
  async submitReview(
    @CurrentUser() user: UserPayload,
    @Param('id') id: string,
    @Body() dto: SubmitReviewDto,
  ) {
    return this.reviewService.submitReview(String(user?.id || 'anonymous'), id, dto);
  }

  @Post('generate-cards')
  @HttpCode(HttpStatus.CREATED)
  @ApiOperation({ summary: 'AI 生成复习卡片' })
  @ApiResponse({ status: 201, description: '卡片生成成功' })
  async generateCards(
    @CurrentUser() user: UserPayload,
    @Body() body: { knowledgeItemTitle: string; knowledgeItemContent: string; cardCount?: number },
  ) {
    return this.reviewService.generateCards(String(user?.id || 'anonymous'), body);
  }
}
