/**
 * @aurora-catalyst-generated
 * @source cliter/iam/account.aurora.yaml
 */
import { IamCheckUniqueUsernameAccountHandler } from '@app/iam/account';
import { Auth } from '@aurora/decorators';
import { Timezone } from '@aurorajs.dev/core-back';
import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';

@ApiTags('[iam] account')
@Controller('iam/account/check-unique-username')
@Auth('iam.account.get')
export class IamCheckUniqueUsernameAccountController {
  constructor(private readonly handler: IamCheckUniqueUsernameAccountHandler) {}

  @Post()
  @HttpCode(200)
  @ApiOperation({ summary: 'check-unique-username account' })
  @ApiOkResponse({
    description:
      'true when the username is available (or only matches the values in avoidUsernames).',
    type: Boolean,
  })
  async main(
    @Body('username') username: string,
    @Body('avoidUsernames') avoidUsernames?: string[],
    @Timezone() timezone?: string,
  ): Promise<boolean> {
    return await this.handler.main(username, avoidUsernames, { timezone });
  }
}
