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 {
  CreateSubjectItemDto,
  UpdateSubjectItemDto,
  PagingSubjectListDto,
  ChangeSubjectStatusDto,
  SubjectDetailsDto,
  SubjectService,
} from '../../service/subject/subject.service';
import { NoAuthToken } from 'src/common/decorator/no-token.decorator';

@ApiTags('训练管理-科目管理-科目')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('train/subject/subject')
export class SubjectController {
  constructor(private readonly subjectService: SubjectService) {}

  /* 
    创建科目
  */
  @Post()
  @ApiOperation({ summary: '创建科目' })
  async create(
    @Body() createClassifyDto: CreateSubjectItemDto,
    @TokenData() token: any,
  ) {
    createClassifyDto.creator = createClassifyDto.updater = token.userId;
    return this.subjectService.create(createClassifyDto, token);
  }
  @Post('/copySubject')
  @ApiOperation({ summary: '复制科目' })
  @NoAuthToken()
  async copy(
    @Body() SubjectDetailsDto: SubjectDetailsDto,
    @TokenData() token: any,
  ) {
    return this.subjectService.copySubject(SubjectDetailsDto);
  }
  @Get('paging')
  @ApiOperation({ summary: '分页获取科目' })
  @NoAuthToken()
  async paging(@Query() pagingInfo: PagingSubjectListDto) {
    return this.subjectService.paging(pagingInfo);
  }
  @Get('details/:id')
  @ApiOperation({ summary: '获取科目详情' })
  @NoAuthToken()
  async details(@Param('id') id: number) {
    return this.subjectService.details(+id);
  }
  /* 
    更新科目
  */
  @Patch('/status')
  @ApiOperation({ summary: '修改科目状态' })
  async changeSubjectStatus(@Body() updateClassifyDto: ChangeSubjectStatusDto) {
    return this.subjectService.changeSubjectStatus(
      +updateClassifyDto.id,
      +updateClassifyDto.status,
    );
  }
  /* 
    更新科目
  */
  @Patch(':id')
  @ApiOperation({ summary: '更新科目' })
  async update(
    @Param('id') id: string,
    @Body() updateClassifyDto: UpdateSubjectItemDto,
  ) {
    return this.subjectService.update(+id, updateClassifyDto);
  }

  /* 
    删除科目
  */
  @Delete('/all')
  @ApiOperation({ summary: '删除科目' })
  async remove(@Body() ids: number[]) {
    return this.subjectService.remove(ids);
  }
}
