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 {
  UpdatePartDto,
  CreatePartDto,
  DevicePartsService,
} from 'src/train/service/device/device-parts.service';

@ApiTags('训练管理-设备管理-部件管理')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('train/device/part')
export class DevicePartController {
  constructor(private readonly devicePartsService: DevicePartsService) {}

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

  @Get(':id')
  @ApiOperation({ summary: '获取部件详情' })
  async findOne(@Param('id') id: number) {
    return this.devicePartsService.findOne(+id);
  }
  @Get('device/:id')
  @ApiOperation({ summary: '获取该设备的所有部件' })
  async findAll(@Param('id') deviceId: number) {
    return this.devicePartsService.findAll(+deviceId);
  }

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

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

  @Delete(':id')
  @ApiOperation({ summary: '删除部件同时删除关联' })
  async remove(@Param('id') id: number) {
    return this.devicePartsService.remove(id);
  }
}
