"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var Three60WhatsappService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Three60WhatsappService = void 0;
const axios_1 = require("@nestjs/axios");
const common_1 = require("@nestjs/common");
const publisher_factory_service_1 = require("../queues/publisher-factory.service");
const whatsapp_provider_decorator_1 = require("../../decorators/whatsapp-provider.decorator");
let Three60WhatsappService = Three60WhatsappService_1 = class Three60WhatsappService {
    constructor(publisherFactory, httpService) {
        this.publisherFactory = publisherFactory;
        this.httpService = httpService;
        this.logger = new common_1.Logger(Three60WhatsappService_1.name);
    }
    async sendWhatsAppMessage(to, templateId, parameters, parentEntity, parentEntityId) {
        const message = {
            payload: {
                to,
                templateId,
                ...parameters,
            },
            parentEntity,
            parentEntityId,
        };
        return this.sendWhatsAppMessageAsynchronously(message);
    }
    async sendWhatsAppMessageAsynchronously(message) {
        const { to, templateId } = message.payload;
        this.logger.debug(`Queueing WhatsApp message to ${to} with template ${templateId}`);
        return this.publisherFactory.publish(message, 'Three60WhatsappQueuePublisher');
    }
    async sendWhatsAppMessageSynchronously(message) {
        throw new Error(`Currently not implemented.`);
    }
};
exports.Three60WhatsappService = Three60WhatsappService;
exports.Three60WhatsappService = Three60WhatsappService = Three60WhatsappService_1 = __decorate([
    (0, common_1.Injectable)(),
    (0, whatsapp_provider_decorator_1.WhatsAppProvider)(),
    __metadata("design:paramtypes", [publisher_factory_service_1.PublisherFactory,
        axios_1.HttpService])
], Three60WhatsappService);
//# sourceMappingURL=Three60WhatsappService.js.map