/**
 * @aurora-catalyst-generated
 * @source cliter/iam/tenant.aurora.yaml
 */
import { IamSequelizeTenantRepository } from '@app/iam/tenant';
import { HandlerMeta } from '@aurorajs.dev/core-back';
import { QueryStatement } from '@aurorajs.dev/core-common';
import { Injectable } from '@nestjs/common';

@Injectable()
export class IamDeleteTenantByIdService {
  constructor(private readonly repository: IamSequelizeTenantRepository) {}

  async main(id: string, constraint?: QueryStatement, handlerMeta?: HandlerMeta): Promise<void> {
    const tenant = await this.repository.findById(id, {
      constraint,
      handlerMeta,
    });

    await this.repository.deleteById(tenant.id, {
      deleteOptions: handlerMeta?.repositoryOptions,
      handlerMeta,
    });
  }
}
