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 {
  UpdatePositionDto,
  CreatePositionDto,
  DeviceNumberPositionService,
} from '../../service/device/device-number-position.service';
import { PaginationDTO } from 'src/assessment-evaluation/dto/pagination.dto';
import { NoAuthToken } from 'src/common/decorator/no-token.decorator';

@ApiTags('训练管理-设备管理-号位管理')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('train/device/position')
export class DeviceNumberPositionController {
  constructor(private readonly classifyService: DeviceNumberPositionService) {}

  @Post()
  @ApiOperation({ summary: '创建号位' })
  async create(
    @Body() createClassifyDto: CreatePositionDto,
    @TokenData() token: any,
  ) {
    createClassifyDto.creator = createClassifyDto.updater = token.userId;
    return await this.classifyService.create(createClassifyDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有号位' })
  async findAll() {
    return this.classifyService.findAll();
  }

  @Get('paging')
  @ApiOperation({ summary: '分页获取号位' })
  @NoAuthToken()
  async paging(@Query() pagingInfo: PaginationDTO) {
    return this.classifyService.paging(pagingInfo);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新号位' })
  async update(
    @Param('id') id: string,
    @Body() updateClassifyDto: UpdatePositionDto,
  ) {
    return this.classifyService.update(+id, updateClassifyDto);
  }

  @Delete('/all')
  @ApiOperation({ summary: '批量删除号位' })
  async remove(@Body() ids: number[]) {
    return this.classifyService.remove(ids);
  }
}
