import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Request,
} from '@nestjs/common';
import { ManualsManageService } from './manuals_manage.service';
import { CreateManualsManageDto } from './dto/create-manuals_manage.dto';
import { UpdateManualsManageDto } from './dto/update-manuals_manage.dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { CreateManualsManageClassifyDto } from './dto/create-manuals_manage_classify.dto';
import { TokenDataEntity } from 'src/common/entities/token-data.entity';
import { TokenData } from 'src/common/decorator/token-data.decorator';
@ApiTags('手册管理')
@Controller('manuals-manage/')
export class ManualsManageController {
  constructor(private readonly manualsManageService: ManualsManageService) {}
  @ApiBearerAuth()
  @Post()
  @ApiOperation({ summary: '新建手册' })
  create(
    @Body() createManualsManageDto: CreateManualsManageDto,
    @TokenData() token: TokenDataEntity,
  ) {
    return this.manualsManageService.create(createManualsManageDto, token);
  }

  // 获取手册分类放在上边！防止GET被抢占
  @Get('classify')
  @ApiOperation({ summary: '查询手册分类' })
  findAllClassify() {
    return this.manualsManageService.findAllClassify();
  }
  // 删除分类
  @ApiOperation({ summary: '删除手册分类' })
  @Delete('classify/:id')
  deleteClassify(@Param('id') id: number) {
    return this.manualsManageService.deleteClassify(id);
  }

  @Get('bycla/:id')
  @ApiOperation({ summary: '根据分类获取手册列表手册' })
  findAllByClassify(
    @Param('id') classifyId: number,
    @TokenData() token: TokenDataEntity,
  ) {
    return this.manualsManageService.findAll(token, classifyId);
  }

  @Get()
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth('jwt')
  @ApiOperation({ summary: '获取手册列表手册' })
  findAll(@TokenData() token: TokenDataEntity) {
    return this.manualsManageService.findAll(token, null);
  }

  @Get(':id')
  @ApiOperation({ summary: '获取单一手册' })
  findOne(@Param('id') id: string, @TokenData() token: TokenDataEntity) {
    return this.manualsManageService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '编辑手册' })
  update(
    @Param('id') id: string,
    @Body() updateManualsManageDto: UpdateManualsManageDto,
    @TokenData() token: TokenDataEntity,
  ) {
    return this.manualsManageService.update(+id, updateManualsManageDto, token);
  }
  @Post('portion')
  @ApiOperation({ summary: '批量更新手册数据' })
  portionUpdate(
    @Body() data: { idArray: []; data: object },
    @TokenData() token: TokenDataEntity,
  ) {
    return this.manualsManageService.portionUpdate(
      data.idArray,
      data.data,
      token,
    );
  }

  @Delete(':id')
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth('jwt')
  @ApiOperation({ summary: '删除手册' })
  remove(@Param('id') id: string) {
    return this.manualsManageService.remove(+id);
  }

  @Post('classify')
  @ApiOperation({ summary: '新建手册分类' })
  createClassify(@Body() data: CreateManualsManageClassifyDto) {
    return this.manualsManageService.createClassify(data);
  }
  @Post('classify/editor')
  @ApiOperation({ summary: '编辑手册分类' })
  editorClassify(@Body() data) {
    return this.manualsManageService.createClassify(data);
  }
}
