"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const addToContactList_1 = __importDefault(require("./addToContactList"));
const removeFromContactList_1 = __importDefault(require("./removeFromContactList"));
const triggerEvent_1 = __importDefault(require("./triggerEvent"));
const upsertContact_1 = __importDefault(require("./upsertContact"));
const emarsys_helper_1 = require("./emarsys-helper");
const destination = {
    name: 'Emarsys (Actions)',
    slug: 'actions-emarsys',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            api_user: {
                label: 'API username',
                description: 'Your Emarsys API username',
                type: 'string',
                required: true
            },
            api_password: {
                label: 'API password',
                description: 'Your Emarsys API password.',
                type: 'password',
                required: true
            }
        },
        testAuthentication: async (request) => {
            const data = await request(`${emarsys_helper_1.API_BASE}settings`);
            if (data && data.content) {
                const api_data = JSON.parse(data.content);
                if (api_data && api_data.replyCode !== undefined && api_data.replyCode == 0) {
                    if (api_data.data && api_data.data.id) {
                        if (api_data.data.id > 0) {
                            return true;
                        }
                    }
                }
            }
            throw new Error('Authentication failed');
        }
    },
    actions: {
        upsertContact: upsertContact_1.default,
        addToContactList: addToContactList_1.default,
        removeFromContactList: removeFromContactList_1.default,
        triggerEvent: triggerEvent_1.default
    },
    extendRequest: ({ settings }) => {
        return {
            headers: { 'X-WSSE': (0, emarsys_helper_1.createWsseHeader)(settings) },
            responseType: 'json'
        };
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map