import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Patch,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { TokenData } from 'src/common/decorator/token-data.decorator';
import { CreateKnowledgePointDto } from 'src/assessment-evaluation/dto/dtos-question-manager/knowledge-point/create-knowledge-point.dto';
import { UpdateKnowledgePointDto } from 'src/assessment-evaluation/dto/dtos-question-manager/knowledge-point/update-knowledge-point.dto';
import { KnowledgePointService } from 'src/assessment-evaluation/service/service-question-manager/knowledge-point.service';

@ApiTags('试题管理 - 知识点管理')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('assessmentEvaluation/knowledgePoint')
export class KnowledgePointController {
  constructor(private readonly KnowledgePointService: KnowledgePointService) {}

  @Post()
  @ApiOperation({
    summary: '新增知识点，会查询知识点是否存在，存在返回旧值，不存在返回新值',
  })
  /* 
  新增知识点，会查询知识点是否存在，存在返回旧值，不存在返回新值
  */
  async create(
    @Body() createKnowledgePointDto: CreateKnowledgePointDto,
    @TokenData() token: any,
  ) {
    createKnowledgePointDto.creator = createKnowledgePointDto.updater =
      token.userId;
    return this.KnowledgePointService.create(createKnowledgePointDto);
  }

  @Get()
  /* 
    获取所有知识点
  */
  async findAll() {
    return this.KnowledgePointService.findAll();
  }

  /* 
    更新知识点
   */
  @Patch(':id')
  async update(
    @Param('id') id: string,
    @Body() updateKnowledgePointDto: UpdateKnowledgePointDto,
  ) {
    return this.KnowledgePointService.update(+id, updateKnowledgePointDto);
  }
  /* 
    删除知识点
  */
  @Delete(':id')
  async remove(@Param('id') id: string) {
    return this.KnowledgePointService.remove(+id);
  }
}
