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 { PaginationDTO } from 'src/assessment-evaluation/dto/pagination.dto';
import { NoAuthToken } from 'src/common/decorator/no-token.decorator';
import {
  UpdateOperationDto,
  CreateOperationDto,
  DevicePartOperationService,
} from 'src/train/service/device/device-part-operation.service';

@ApiTags('训练管理-设备管理-部件状态管理')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('train/device/operation')
export class DevicePartOperationController {
  constructor(
    private readonly devicePartOperationService: DevicePartOperationService,
  ) {}

  @Post()
  @ApiOperation({ summary: '创建部件状态' })
  async create(
    @Body() createClassifyDto: CreateOperationDto,
    @TokenData() token: any,
  ) {
    createClassifyDto.creator = createClassifyDto.updater = token.userId;
    return this.devicePartOperationService.create(createClassifyDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有部件状态' })
  async findAll() {
    return this.devicePartOperationService.findAll();
  }

  @Get('paging')
  @ApiOperation({ summary: '分页获取部件状态' })
  @NoAuthToken()
  async paging(@Query() pagingInfo: PaginationDTO) {
    return this.devicePartOperationService.paging(pagingInfo);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新部件状态' })
  async update(
    @Param('id') id: string,
    @Body() updateClassifyDto: UpdateOperationDto,
  ) {
    return this.devicePartOperationService.update(+id, updateClassifyDto);
  }

  @Delete('/all')
  @ApiOperation({ summary: '批量删除部件状态' })
  async remove(@Body() ids: number[]) {
    return this.devicePartOperationService.remove(ids);
  }
}
