import {
  Inject,
  Param,
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Delete,
  UseGuards,
  ParseIntPipe,
  NotFoundException,
  HttpException,
  HttpStatus,
} from '@nestjs/common';
import {
  ApiCreatedResponse,
  ApiOkResponse,
  ApiNotFoundResponse,
  ApiTags,
} from '@nestjs/swagger';
import {
  PageOptionsDto,
  ApiPaginatedResponse,
  PageDto,
  PageMetaDto,
  ACGuard,
  ACAttrFilter,
  excludeEndpoint,
  excludeController,
} from '@gadmin2/nest-common';
import {
  UseRoles,
  RolesBuilder,
  InjectRolesBuilder,
} from 'nest-access-control';
<% if(hasGenerated) { %>
import { <%= classify(name) %>Service } from '../../generated/<%= name %>/<%= name %>.service';
import { <%= classify(name) %>Controller as Generated<%= classify(name) %>Controller } from '../../generated/<%= name %>/<%= name %>.controller';
import { Create<%= classify(name) %>Dto } from '../../generated/<%= name %>/dto/create-<%= name %>.dto';
import { Update<%= classify(name) %>Dto } from '../../generated/<%= name %>/dto/update-<%= name %>.dto';
import { <%= classify(name) %>Entity } from '../../generated/<%= name %>/entities/<%= name %>.entity';
<% } %>
import { PrismaService } from 'nestjs-prisma';
import { Prisma } from '@prisma/client';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston';

import { ConfigService } from '@nestjs/config';

<% if(hasGenerated) { %>
// excludeController(Generated<%= classify(name) %>Controller);
// excludeEndpoint(Generated<%= classify(name) %>Controller, 'deleteUinque');
<% } %>

@UseGuards(ACGuard)
@Controller('<%= name %>')
@ApiTags('<%= name %>')
export class <%= classify(name) %>Controller {
  constructor(
    <% if(hasGenerated) { %>
    private readonly <%= name %>Service: <%= classify(name) %>Service,
    <% } %>
    private prisma: PrismaService,
    private readonly config: ConfigService,
    @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
    @InjectRolesBuilder() private readonly ac: RolesBuilder,
  ) {}

  /*
  @Get('findUnique/:id')
  @ApiOkResponse({
    description: 'Return input id.',
    type: String,
  })
  findUnique(@Param('id') id: string): string {
    return id;
  }
*/
<% if(hasGenerated) { %>
  /*
  @Post('create')
  @UseRoles({
    resource: '<%= name %>',
    action: 'create',
    possession: 'any',
  })
  @ApiCreatedResponse({ type: <%= classify(name) %>Entity })
  async create(
    @Body() create<%= classify(name) %>Dto: Create<%= classify(name) %>Dto,
    @ACAttrFilter() acAttrFilter,
  ) {
    return new <%= classify(name) %>Entity(
      await this.<%= name %>Service.create(acAttrFilter(create<%= classify(name) %>Dto)),
    );
  }
*/

  /*
  @Patch(':id')
  @UseRoles({
    resource: '<%= name %>',
    action: 'update',
    possession: 'own',
  })
  @ApiOkResponse({ type: UniqueEffectedCount })
  @ApiNotFoundResponse({
    description: 'Cannot found this record or this record is not belong you.',
  })
  async updateOwn(
    @Param('id', ParseIntPipe) id: number,
    @Body() update<%= classify(name) %>Dto: Update<%= classify(name) %>Dto,
    @User() { roles, username }: UserType,
    @ACAttrFilter() acAttrFilter,
  ) {
    if (!this.ac.can(roles).updateAny('<%= name %>').granted) {
      const res = await this.<%= name %>Service.findUnique(id);
      if(!res) {
        throw new NotFoundException();
      }

      if (res.creator !== username) {
        throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
      }
    }
    const res = await this.<%= name %>Service.updateUnique(
      id,
      acAttrFilter(update<%= classify(name) %>Dto),
    );
    if (!res.count) {
      throw new NotFoundException();
    }
    return res;
  }
*/
<% } %>
}
