/**
 * @aurora-catalyst-generated
 * @source cliter/iam/account.aurora.yaml
 */
import { IamAccount } from '@api/graphql';
import { IamAccountDto, IamCreateAccountDto } from '@api/iam/account';
import { IamCreateAccountHandler } from '@app/iam/account';
import { Auth } from '@aurora/decorators';
import { Auditing, AuditingMeta, CurrentAccount, Timezone } from '@aurorajs.dev/core-back';
import { Body, Controller, Post } from '@nestjs/common';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';

@ApiTags('[iam] account')
@Controller('iam/account/create')
@Auth('iam.account.create')
export class IamCreateAccountController {
  constructor(private readonly handler: IamCreateAccountHandler) {}

  @Post()
  @ApiOperation({ summary: 'Create account' })
  @ApiCreatedResponse({
    description: 'The record has been successfully created.',
    type: IamAccountDto,
  })
  async main(
    @CurrentAccount() currentAccount: IamAccount,
    @Body() payload: IamCreateAccountDto,
    @Timezone() timezone?: string,
    @Auditing() auditing?: AuditingMeta,
  ) {
    return await this.handler.main(currentAccount, payload, {
      timezone,
      repositoryOptions: { auditing },
    });
  }
}
