/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/application-client.aurora.yaml
 */
import { OAuthSequelizeApplicationClientRepository } from '@app/o-auth/application-client';
import { HandlerMeta } from '@aurorajs.dev/core-back';
import { QueryStatement } from '@aurorajs.dev/core-common';
import { Injectable } from '@nestjs/common';

@Injectable()
export class OAuthDeleteApplicationClientByIdService {
  constructor(private readonly repository: OAuthSequelizeApplicationClientRepository) {}

  async main(
    applicationId: string,
    clientId: string,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<void> {
    const applicationClient = await this.repository.findById(undefined, {
      constraint,
      handlerMeta,
      findArguments: {
        applicationId: applicationId,
        clientId: clientId,
      },
    });

    await this.repository.deleteById(undefined, {
      deleteOptions: handlerMeta?.repositoryOptions,
      handlerMeta,
      findArguments: {
        applicationId: applicationClient.applicationId,
        clientId: applicationClient.clientId,
      },
    });
  }
}
