/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/credential.aurora.yaml
 */
import { OAuthCredentialDto } from '@api/o-auth/credential';
import { OAuthGetCredentialsHandler } from '@app/o-auth/credential';
import { Auth } from '@aurora/decorators';
import { Timezone } from '@aurorajs.dev/core-back';
import { QueryStatement } from '@aurorajs.dev/core-common';
import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import { ApiBody, ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';

@ApiTags('[o-auth] credential')
@Controller('o-auth/credentials/get')
@Auth('oAuth.credential.get')
export class OAuthGetCredentialsController {
  constructor(private readonly handler: OAuthGetCredentialsHandler) {}

  @Post()
  @HttpCode(200)
  @ApiOperation({ summary: 'Get credentials according to query' })
  @ApiOkResponse({
    description: 'The records has been found successfully.',
    type: [OAuthCredentialDto],
  })
  @ApiBody({ type: QueryStatement })
  @ApiQuery({ name: 'query', type: QueryStatement })
  async main(
    @Body('query') queryStatement?: QueryStatement,
    @Body('constraint') constraint?: QueryStatement,
    @Timezone() timezone?: string,
  ) {
    return await this.handler.main(queryStatement, constraint, {
      timezone,
    });
  }
}
