import { Controller } from '@nestjs/common';
import { CustomerverificationsService } from './customerverifications.service';
import { MessagePattern, RpcException } from '@nestjs/microservices';

@Controller()
export class CustomerverificationsController {
  constructor(
    private readonly customerVerificationService: CustomerverificationsService,
  ) {}

  @MessagePattern({ cmd: 'customer_verification_getAll' })
  async getAll(data: {}): Promise<any> {
    try {
      const getAllData = await this.customerVerificationService.getAll();
      return getAllData;
    } catch (err) {
      console.log(err);
      throw new RpcException('Failed to retrieve customer verifications ');
    }
  }

  @MessagePattern({ cmd: 'customer_verification_get_by_customer' })
  async getVerificationByCustomerId(data: { id: number }) {
    try {
      const { id } = data;
      const result =
        await this.customerVerificationService.getVerificationByCustomerId(id);
      return result;
    } catch (err) {
      console.log(err);
      throw new RpcException('Failed to retrieve customer verifications ');
    }
  }
}
