import { Controller, Post, Get, Param, Body } from '@nestjs/common'
import { InterviewService } from './interview.service'
import { CurrentUser } from '../../common/decorators/current-user.decorator'

@Controller('interview')
export class InterviewController {
  constructor(private interviewService: InterviewService) {}

  // 静态路由必须放在 :id 动态路由之前

  @Get('list/all')
  async getList(@CurrentUser('userId') userId: string) {
    return this.interviewService.getList(userId)
  }

  @Get('stats/mine')
  async getStats(@CurrentUser('userId') userId: string) {
    return this.interviewService.getStats(userId)
  }

  @Post('create')
  async create(@CurrentUser('userId') userId: string, @Body('position') position: string) {
    return this.interviewService.create(userId, position)
  }

  @Post(':id/answer')
  async answer(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
    @Body('answer') answer: string,
    @Body('avatar') avatar?: boolean,
  ) {
    if (avatar) return this.interviewService.answerWithAvatar(id, userId, answer)
    return this.interviewService.answer(id, userId, answer)
  }

  @Post(':id/complete')
  async complete(@Param('id') id: string, @CurrentUser('userId') userId: string) {
    return this.interviewService.complete(id, userId)
  }

  @Get(':id')
  async getDetail(@Param('id') id: string, @CurrentUser('userId') userId: string) {
    return this.interviewService.getDetail(id, userId)
  }
}
