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);
};
import { AppApiHostname } from "../EnvironmentConfig";
import ClusterKeyAuthorization from "../Middleware/ClusterKeyAuthorization";
import BaseService from "./BaseService";
import Protocol from "../../Types/API/Protocol";
import Route from "../../Types/API/Route";
import URL from "../../Types/API/URL";
import API from "../../Utils/API";
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
export class WhatsAppService extends BaseService {
    constructor() {
        super();
    }
    async sendWhatsAppMessage(message, options = {}) {
        const body = {
            to: message.to.toString(),
        };
        if (message.body) {
            body["body"] = message.body;
        }
        if (message.templateKey) {
            body["templateKey"] = message.templateKey;
        }
        if (message.templateVariables) {
            const templateVariables = {};
            for (const [key, value] of Object.entries(message.templateVariables)) {
                templateVariables[key] = value;
            }
            body["templateVariables"] = templateVariables;
        }
        if (message.templateLanguageCode) {
            body["templateLanguageCode"] = message.templateLanguageCode;
        }
        if (options.projectId) {
            body["projectId"] = options.projectId.toString();
        }
        if (options.isSensitive !== undefined) {
            body["isSensitive"] = options.isSensitive;
        }
        if (options.userOnCallLogTimelineId) {
            body["userOnCallLogTimelineId"] =
                options.userOnCallLogTimelineId.toString();
        }
        if (options.incidentId) {
            body["incidentId"] = options.incidentId.toString();
        }
        if (options.alertId) {
            body["alertId"] = options.alertId.toString();
        }
        if (options.alertEpisodeId) {
            body["alertEpisodeId"] = options.alertEpisodeId.toString();
        }
        if (options.monitorId) {
            body["monitorId"] = options.monitorId.toString();
        }
        if (options.scheduledMaintenanceId) {
            body["scheduledMaintenanceId"] =
                options.scheduledMaintenanceId.toString();
        }
        if (options.statusPageId) {
            body["statusPageId"] = options.statusPageId.toString();
        }
        if (options.statusPageAnnouncementId) {
            body["statusPageAnnouncementId"] =
                options.statusPageAnnouncementId.toString();
        }
        if (options.userId) {
            body["userId"] = options.userId.toString();
        }
        if (options.onCallPolicyId) {
            body["onCallPolicyId"] = options.onCallPolicyId.toString();
        }
        if (options.onCallPolicyEscalationRuleId) {
            body["onCallPolicyEscalationRuleId"] =
                options.onCallPolicyEscalationRuleId.toString();
        }
        if (options.onCallDutyPolicyExecutionLogTimelineId) {
            body["onCallDutyPolicyExecutionLogTimelineId"] =
                options.onCallDutyPolicyExecutionLogTimelineId.toString();
        }
        if (options.onCallScheduleId) {
            body["onCallScheduleId"] = options.onCallScheduleId.toString();
        }
        if (options.teamId) {
            body["teamId"] = options.teamId.toString();
        }
        return await API.post({
            url: new URL(Protocol.HTTP, AppApiHostname, new Route("/api/notification/whatsapp/send")),
            data: body,
            headers: Object.assign({}, ClusterKeyAuthorization.getClusterKeyHeaders()),
        });
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], WhatsAppService.prototype, "sendWhatsAppMessage", null);
export default new WhatsAppService();
//# sourceMappingURL=WhatsAppService.js.map