"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const updateUserProfile_1 = __importDefault(require("./updateUserProfile"));
const actions_core_1 = require("@segment/actions-core");
const trackEvent_1 = __importDefault(require("./trackEvent"));
const utilities_1 = require("./utilities");
const destination = {
    name: 'Pushwoosh',
    slug: 'actions-pushwoosh',
    mode: 'cloud',
    description: 'Pushwoosh(https://www.pushwoosh.com) provides a customer engagement platform for mobile apps and websites and brings together all essential communication tools within one platform.' +
        'Through the integration with Segment, Pushwoosh can leverage the comprehensive customer data collected, ensuring highly personalized and effective communication strategies.',
    authentication: {
        scheme: 'custom',
        fields: {
            pushwooshAPIKey: {
                label: 'Pushwoosh API Key',
                description: 'Pushwoosh API Key from Pushwoosh Control Panel',
                type: 'password',
                required: true
            },
            pushwooshAppCode: {
                label: 'Pushwoosh Application Code',
                description: 'Pushwoosh Application Code from Pushwoosh Control Panel',
                type: 'string',
                required: true
            }
        },
        testAuthentication: (request) => {
            const endpoint = (0, utilities_1.getEndpoint)('/integration-segment/v1/ping');
            return request(endpoint, {
                method: 'post',
                json: {
                    body: {
                        name: 'test_segment_auth'
                    }
                }
            });
        }
    },
    presets: [
        {
            name: 'Track Events',
            subscribe: 'type = "track" or type = "page" or type = "screen"',
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Create or Update User Profile',
            subscribe: 'type = "identify"',
            partnerAction: 'updateUserProfile',
            mapping: (0, actions_core_1.defaultValues)(updateUserProfile_1.default.fields),
            type: 'automatic'
        }
    ],
    onDelete: async (request, { payload }) => {
        const endpoint = (0, utilities_1.getEndpoint)('/integration-segment/v1/delete-user');
        return request(endpoint, {
            method: 'post',
            json: {
                external_id: payload.userId
            }
        });
    },
    extendRequest({ settings }) {
        return {
            headers: {
                Authorization: `Token ${settings.pushwooshAPIKey}`,
                'X-PW-Appcode': `${settings.pushwooshAppCode}`
            }
        };
    },
    actions: {
        updateUserProfile: updateUserProfile_1.default,
        trackEvent: trackEvent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map