/**
 * @aurora-catalyst-generated
 * @source cliter/iam/role-account.aurora.yaml
 */
import { IamRoleAccount } from '@api/graphql';
import { IamSequelizeRoleAccountRepository } from '@app/iam/role-account';
import { HandlerMeta } from '@aurorajs.dev/core-back';
import { Injectable } from '@nestjs/common';

@Injectable()
export class IamCreateRoleAccountService {
  constructor(private readonly repository: IamSequelizeRoleAccountRepository) {}

  async main(payload: any, handlerMeta?: HandlerMeta): Promise<void> {
    await this.repository.create(payload, {
      createOptions: handlerMeta?.repositoryOptions,
      finderQueryStatement: (aggregate: IamRoleAccount) => ({
        where: {
          roleId: aggregate.roleId,
          accountId: aggregate.accountId,
        },
      }),
    });
  }
}
