import type { EventDidcommConnectionsBlockInput, EventDidcommConnectionsGetAllInput, EventDidcommConnectionsGetByIdInput, } from '@ocm/shared'; import type { Observable } from 'rxjs'; import { Inject, Injectable } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { EventDidcommConnectionsBlock, EventDidcommConnectionsCreateWithSelf, EventDidcommConnectionsGetAll, EventDidcommConnectionsGetById, } from '@ocm/shared'; import { map } from 'rxjs'; import { NATS_CLIENT } from '../common/constants.js'; @Injectable() export class ConnectionsService { public constructor( @Inject(NATS_CLIENT) private readonly natsClient: ClientProxy, ) {} public getAllConnections( tenantId: string, ): Observable<EventDidcommConnectionsGetAll['data']> { return this.natsClient .send< EventDidcommConnectionsGetAll, EventDidcommConnectionsGetAllInput >(EventDidcommConnectionsGetAll.token, { tenantId }) .pipe(map((result) => result.data)); } public getConnectionById( tenantId: string, id: string, ): Observable<EventDidcommConnectionsGetById['data']> { return this.natsClient .send< EventDidcommConnectionsGetById, EventDidcommConnectionsGetByIdInput >(EventDidcommConnectionsGetById.token, { tenantId, id }) .pipe(map((result) => result.data)); } public createConnectionWithSelf( tenantId: string, ): Observable<EventDidcommConnectionsCreateWithSelf['data']> { return this.natsClient .send<EventDidcommConnectionsCreateWithSelf>( EventDidcommConnectionsCreateWithSelf.token, { tenantId }, ) .pipe(map((result) => result.data)); } public blockConnection( tenantId: string, idOrDid: string, ): Observable<EventDidcommConnectionsBlock['data']> { return this.natsClient .send< EventDidcommConnectionsBlock, EventDidcommConnectionsBlockInput >(EventDidcommConnectionsBlock.token, { tenantId, idOrDid }) .pipe(map((result) => result.data)); } }