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 {
  CreateTrainTypeDto,
  UpdateTrainTypeDto,
  TrainTypeService,
} from '../../service/subject/train-type.service';

@ApiTags('训练管理-科目管理-训练类型')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('train/subject/traintype')
export class TrainTypeController {
  constructor(private readonly classifyService: TrainTypeService) {}

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

  /* 
    获取所有训练类型
  */
  @Get('')
  @ApiOperation({ summary: '获取所有训练类型' })
  async findAll() {
    return this.classifyService.findAll();
  }

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

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