"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const identifyUser_1 = __importDefault(require("./identifyUser"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const identifyGroup_1 = __importDefault(require("./identifyGroup"));
const presets = [
    {
        name: 'Track Events',
        subscribe: 'type = "track"',
        partnerAction: 'trackEvent',
        mapping: { ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields) },
        type: 'automatic'
    },
    {
        name: 'Identify Calls',
        subscribe: 'type = "identify"',
        partnerAction: 'identifyUser',
        mapping: { ...(0, actions_core_1.defaultValues)(identifyUser_1.default.fields) },
        type: 'automatic'
    },
    {
        name: 'Group Calls',
        subscribe: 'type = "group"',
        partnerAction: 'identifyGroup',
        mapping: { ...(0, actions_core_1.defaultValues)(identifyGroup_1.default.fields) },
        type: 'automatic'
    }
];
const destination = {
    name: 'Survicate Cloud Mode (Actions)',
    slug: 'actions-survicate-cloud',
    mode: 'cloud',
    description: 'Sync Segment analytics events, user profile and company profile details to Survicate.',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'Destination Key',
                description: 'Your Survicate Destination Key, which you can find in Survicate - Integrations - Segment (Cloud Mode, Actions) - Settings.',
                type: 'password',
                required: true
            }
        },
        testAuthentication: async (request, { settings }) => {
            return request(`https://integrations.survicate.com/endpoint/segment/check`, {
                method: 'get',
                headers: {
                    Authorization: `Bearer ${settings.apiKey}`,
                    'Content-Type': 'application/json'
                }
            });
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                Authorization: `Bearer ${settings.apiKey}`,
                'Content-Type': 'application/json'
            }
        };
    },
    presets,
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default,
        identifyGroup: identifyGroup_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map