import { BaseController } from '@/common/base';
import { Respond, RespondType } from '@/common/response';
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, Version } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Create{{upcaseName name}}Dto } from './dto/create-{{fileName name}}.dto';
import { Find{{upcaseName name}}Dto } from './dto/find-{{fileName name}}.dto';
import { Update{{upcaseName name}}Dto } from './dto/update-{{fileName name}}.dto';
import { {{upcaseName name}} } from './entities/{{fileName name}}.entity';
import { {{upcaseName name}}Service } from './{{fileName name}}.service';

@ApiTags('{{fileName name}}')
@Controller('{{lowcaseName name}}s')
export class {{upcaseName name}}Controller extends BaseController {
  constructor(private {{lowcaseName name}}Service: {{upcaseName name}}Service) {
    super();
  }

  @Post()
  @ApiOperation({ description: '创建{{cnName}}', operationId: 'add{{upcaseName name}}' })
  create(@Body() create{{upcaseName name}}Dto: Create{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.create(create{{upcaseName name}}Dto);
  }

  @Get()
  @Respond(RespondType.PAGINATION)
  @ApiOkResponse({ isArray: true, type: {{upcaseName name}} })
  @ApiOperation({ description: '批量查询{{cnName}}', operationId: 'get{{upcaseName name}}s' })
  async findMany(@Query() query: Find{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.findMany(query);
  }

  @Patch(':id')
  @ApiOperation({ description: '更新{{cnName}}', operationId: 'update{{upcaseName name}}' })
  update(@Param('id') id: number, @Body() update{{upcaseName name}}Dto: Update{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.update(+id, update{{upcaseName name}}Dto);
  }

  @Delete(':id')
  @ApiOperation({ description: '删除{{cnName}}', operationId: 'delete{{upcaseName name}}' })
  remove(@Param('id') id: number) {
    return this.{{lowcaseName name}}Service.remove(+id);
  }
}
