import { ApiCommonErrorResponses, FilterArgs, RoleEnum, Roles } from '<%= props.frameworkImport %>';
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
import { ApiOkResponse } from '@nestjs/swagger';

import { <%= props.namePascal %>Service } from './<%= props.nameKebab %>.service';
import { <%= props.namePascal %>Input } from './inputs/<%= props.nameKebab %>.input';
import { <%= props.namePascal %>CreateInput } from './inputs/<%= props.nameKebab %>-create.input';
import { <%= props.namePascal %> } from './<%= props.nameKebab %>.model';

@ApiCommonErrorResponses()
@Controller('<%= props.lowercase %>')
@Roles(RoleEnum.ADMIN)
export class <%= props.namePascal %>Controller {

constructor(protected readonly <%= props.nameCamel %>Service: <%= props.namePascal %>Service) {}

  @ApiOkResponse({ type: <%= props.namePascal %> })
  @Post()
  @Roles(RoleEnum.S_USER)
  async create(@Body() input: <%= props.namePascal %>CreateInput): Promise<<%= props.namePascal %>> {
    return await this.<%= props.nameCamel %>Service.create(input);
  }

  @ApiOkResponse({ description: 'Find and count <%= props.namePascal %>' })
  @Get('find-and-count')
  @Roles(RoleEnum.S_USER)
  async findAndCount(@Body() filterArgs: FilterArgs): Promise<{ items: <%= props.namePascal %>[]; totalCount: number }> {
    return await this.<%= props.nameCamel %>Service.findAndCount(filterArgs);
  }

  @ApiOkResponse({ isArray: true, type: <%= props.namePascal %> })
  @Get()
  @Roles(RoleEnum.S_USER)
  async get(@Body() filterArgs: FilterArgs): Promise<<%= props.namePascal %>[]> {
    return await this.<%= props.nameCamel %>Service.find(filterArgs);
  }

  @ApiOkResponse({ type: <%= props.namePascal %> })
  @Get(':id')
  @Roles(RoleEnum.S_USER)
  async getById(@Param('id') id: string): Promise<<%= props.namePascal %>> {
    return await this.<%= props.nameCamel %>Service.findOne({filterQuery: { _id: id }});
  }

  @ApiOkResponse({ type: <%= props.namePascal %> })
  @Put(':id')
  @Roles(RoleEnum.S_USER)
  async update(@Param('id') id: string, @Body() input: <%= props.namePascal %>Input): Promise<<%= props.namePascal %>> {
    return await this.<%= props.nameCamel %>Service.update(id, input, {
      roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR],
    });
  }

  @ApiOkResponse({ type: <%= props.namePascal %> })
  @Delete(':id')
  @Roles(RoleEnum.S_USER)
  async delete(@Param('id') id: string): Promise<<%= props.namePascal %>> {
    return await this.<%= props.nameCamel %>Service.delete(id, {
      roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR],
    });
  }

}
