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

@ApiTags('[iam] account')
@Controller('iam/account/update')
@Auth('iam.account.update')
export class IamUpdateAccountByIdController {
  constructor(private readonly handler: IamUpdateAccountByIdHandler) {}

  @Put()
  @ApiOperation({ summary: 'Update account by id' })
  @ApiOkResponse({ description: 'The record has been successfully updated.', type: IamAccountDto })
  async main(
    @CurrentAccount() currentAccount: IamAccount,
    @Body() payload: IamUpdateAccountByIdDto,
    @Body('constraint') constraint?: QueryStatement,
    @Timezone() timezone?: string,
    @Auditing() auditing?: AuditingMeta,
  ) {
    return await this.handler.main(currentAccount, payload, constraint, {
      timezone,
      repositoryOptions: { auditing },
    });
  }
}
