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 {
  UpdateClassifyDto,
  CreateClassifyDto,
  DeviceClassifyService,
} from '../../service/device/device-classify.service';

@ApiTags('训练管理-设备管理-设备分类')
@ApiBearerAuth()
// @NoAuthToken()
@Controller('train/device/classify')
export class DeviceClassifyController {
  constructor(private readonly classifyService: DeviceClassifyService) {}

  /* 
    创建分类
  */
  @Post()
  @ApiOperation({ summary: '创建分类' })
  async create(
    @Body() createClassifyDto: CreateClassifyDto,
    @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: UpdateClassifyDto,
  ) {
    return this.classifyService.update(+id, updateClassifyDto);
  }

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