import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
import { NotificationhubService } from '../../gateways/notificationhub/notificationhub.service';

@Injectable()
export class NotificationService {
  private readonly logger = new Logger(NotificationService.name);
  constructor(
    private readonly notificationhubService: NotificationhubService,
  ) {}
  /**
   * Registers notification service
   * @param pns
   * @param pnsHandler
   * @returns register
   */
  async register(pns: string, pnsHandler: string): Promise<void> {
    this.logger.log(`[IN] ${this.register.name}`);
    try {
      await this.notificationhubService.register(pns, pnsHandler);
    } catch (e) {
      this.logger.error(`error=${e}`);
      throw new HttpException(
        makeErrorResponse('E009999'),
        HttpStatus.INTERNAL_SERVER_ERROR,
      );
    } finally {
      this.logger.log(`[OUT] ${this.register.name}`);
    }
  }
}
