"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 request_utils_1 = require("./request-utils");
const identifyUser_1 = __importDefault(require("./identifyUser"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const identifyCompany_1 = __importDefault(require("./identifyCompany"));
const destination = {
    name: 'Userpilot Cloud (Actions)',
    slug: 'actions-userpilot-cloud',
    mode: 'cloud',
    presets: [
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: (0, actions_core_1.defaultValues)(identifyUser_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Identify Company',
            subscribe: 'type = "group"',
            partnerAction: 'identifyCompany',
            mapping: (0, actions_core_1.defaultValues)(identifyCompany_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Track Event',
            subscribe: 'type = "track"',
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        }
    ],
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'API Key',
                description: 'Your Userpilot API key can be found in the [Userpilot environment](https://run.userpilot.io/environment) dashboard.',
                type: 'password',
                required: true
            },
            endpoint: {
                label: 'API Endpoint',
                description: 'Your Userpilot API endpoint can be found in the [Userpilot environment](https://run.userpilot.io/environment) dashboard.',
                type: 'string',
                required: true,
                default: 'https://analytex.userpilot.io/'
            }
        },
        testAuthentication: (request, { settings }) => {
            const { url, options } = (0, request_utils_1.getValidationParams)(settings);
            return request(url, options);
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                'Content-Type': 'application/json',
                Authorization: `Token ${settings.apiKey}`,
                'X-API-Version': '2020-09-22'
            }
        };
    },
    onDelete: async (request, { settings, payload }) => {
        const { userId } = payload;
        const { url, options } = (0, request_utils_1.getDeleteRequestParams)(settings, userId ?? '');
        return request(url, options);
    },
    actions: {
        identifyUser: identifyUser_1.default,
        trackEvent: trackEvent_1.default,
        identifyCompany: identifyCompany_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map