"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 constants_1 = require("./constants");
const trackEvent_1 = __importDefault(require("./trackEvent"));
const syncToUserGroup_1 = __importDefault(require("./syncToUserGroup"));
const presets = [
    {
        name: 'Track User Actions',
        subscribe: 'type = "track"',
        partnerAction: 'trackEvent',
        mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
        type: 'automatic'
    },
    {
        name: 'Page Calls',
        subscribe: 'type = "page"',
        partnerAction: 'trackEvent',
        mapping: {
            ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            event_name: {
                '@if': {
                    exists: { '@path': '$.name' },
                    then: { '@path': '$.name' },
                    else: { '@path': '$.properties.title' }
                }
            }
        },
        type: 'automatic'
    },
    {
        name: 'Screen Calls',
        subscribe: 'type = "screen"',
        partnerAction: 'trackEvent',
        mapping: {
            ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            event_name: {
                '@if': {
                    exists: { '@path': '$.name' },
                    then: { '@path': '$.name' },
                    else: { '@path': '$.properties.title' }
                }
            }
        },
        type: 'automatic'
    }
];
const destination = {
    name: 'LiveLike',
    slug: 'actions-livelike-cloud',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            clientId: {
                label: 'Client ID',
                description: 'Your LiveLike Application Client ID.',
                type: 'string',
                required: true
            },
            producerToken: {
                label: 'Producer Token',
                description: 'Your LiveLike Producer token.',
                type: 'password',
                required: true
            }
        },
        testAuthentication: async (request, { settings }) => {
            return request(`${constants_1.apiBaseUrl}/applications/${settings.clientId}/validate-app/`, {
                method: 'get'
            });
        }
    },
    extendRequest: ({ settings }) => {
        return {
            headers: { Authorization: `Bearer ${settings.producerToken}` }
        };
    },
    presets,
    actions: {
        trackEvent: trackEvent_1.default,
        syncToUserGroup: syncToUserGroup_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map