import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Patch,
  Query,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { TokenData } from 'src/common/decorator/token-data.decorator';
import {
  CreateSubjectClassifyDto,
  UpdateSubjectClassifyDto,
  SubjectClassifyService,
  FindClassifyByTypeDto,
} from '../../service/subject/subject-classify.service';

@ApiTags('训练管理-科目管理-分类')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('train/subject/classify')
export class SubjectClassifyController {
  constructor(private readonly classifyService: SubjectClassifyService) {}

  /* 
    创建分类
  */
  @Post()
  @ApiOperation({ summary: '创建分类' })
  async create(
    @Body() createClassifyDto: CreateSubjectClassifyDto,
    @TokenData() token: any,
  ) {
    createClassifyDto.creator = createClassifyDto.updater = token.userId;
    return this.classifyService.create(createClassifyDto);
  }

  /* 
    获取所有分类
  */
  @Get('')
  @ApiOperation({ summary: '根据训练类型获取所有分类' })
  async findAll(@Query() query: FindClassifyByTypeDto) {
    return this.classifyService.findAll(query.id);
  }

  /* 
    更新分类
  */
  @Patch(':id')
  @ApiOperation({ summary: '更新分类' })
  async update(
    @Param('id') id: string,
    @Body() updateClassifyDto: UpdateSubjectClassifyDto,
  ) {
    return this.classifyService.update(+id, updateClassifyDto);
  }

  /* 
    删除分类
  */
  @Delete(':id')
  @ApiOperation({ summary: '删除分类' })
  async remove(@Param('id') id: string) {
    return this.classifyService.remove(+id);
  }
}
