"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dd_api_1 = __importDefault(require("../dd-api"));
class DDContactApi extends dd_api_1.default {
    constructor(settings, client) {
        super(settings, client);
    }
    async getContact(idType, idValue) {
        const response = await this.get(`/contacts/v3/${idType}/${idValue}`);
        return response.data;
    }
    async fetchOrCreateContact(channelIdentifier, data) {
        const [[idType, idValue]] = Object.entries(channelIdentifier);
        const response = await this.patch(`/contacts/v3/${idType}/${idValue}`, data);
        return response.data;
    }
    async upsertContact(payload) {
        const { channelIdentifier, emailIdentifier, mobileNumberIdentifier, listId, dataFields } = payload;
        const idValue = channelIdentifier === 'email' ? emailIdentifier : mobileNumberIdentifier;
        const identifiers = {
            ...(emailIdentifier && { email: emailIdentifier }),
            ...(mobileNumberIdentifier && { mobileNumber: mobileNumberIdentifier })
        };
        const channelProperties = {
            ...(emailIdentifier && {
                email: {
                    status: 'subscribed',
                    emailType: 'html',
                    optInType: 'single'
                }
            }),
            ...(mobileNumberIdentifier && {
                sms: { status: 'subscribed' }
            })
        };
        const data = {
            identifiers,
            channelProperties,
            lists: [listId],
            dataFields: dataFields
        };
        const response = await this.patch(`/contacts/v3/${channelIdentifier}/${idValue}?merge-option=overwrite`, data);
        return response.data;
    }
}
exports.default = DDContactApi;
//# sourceMappingURL=dd-contact-api.js.map