/**
 * @aurora-catalyst-generated
 * @source cliter/iam/account.aurora.yaml
 */
import { IamCheckUniqueEmailAccountHandler } 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-email')
@Auth('iam.account.get')
export class IamCheckUniqueEmailAccountController {
  constructor(private readonly handler: IamCheckUniqueEmailAccountHandler) {}

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