"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 pageVisit_1 = __importDefault(require("./pageVisit"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const identifyUser_1 = __importDefault(require("./identifyUser"));
const syncAudience_1 = __importDefault(require("./syncAudience"));
const destination = {
    name: 'VWO Cloud Mode (Actions)',
    slug: 'actions-vwo-cloud',
    mode: 'cloud',
    presets: [
        {
            name: 'Track Event',
            subscribe: 'type = "track"',
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: (0, actions_core_1.defaultValues)(identifyUser_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Page Visit',
            subscribe: 'type = "page"',
            partnerAction: 'pageVisit',
            mapping: (0, actions_core_1.defaultValues)(pageVisit_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Sync Audience',
            subscribe: 'event = "Audience Entered" or event = "Audience Exited"',
            partnerAction: 'syncAudience',
            mapping: (0, actions_core_1.defaultValues)(syncAudience_1.default.fields),
            type: 'automatic'
        }
    ],
    authentication: {
        scheme: 'custom',
        fields: {
            vwoAccountId: {
                label: 'Your VWO account ID',
                description: 'Enter your VWO Account ID',
                type: 'number',
                required: true
            },
            apikey: {
                label: 'VWO SDK Key',
                description: 'VWO Fullstack SDK Key. It is mandatory when using the VWO Fullstack suite.',
                type: 'password',
                required: false
            },
            region: {
                label: 'Region',
                description: 'VWO Region to sync data to. Default is US',
                type: 'string',
                choices: [
                    { label: 'US', value: 'US' },
                    { label: 'Europe', value: 'EU' },
                    { label: 'Asia', value: 'AS' }
                ],
                default: 'US'
            }
        },
        testAuthentication: (_request, { settings }) => {
            if (settings.vwoAccountId < 1 || settings.vwoAccountId.toString().length > 7) {
                throw new Error('Invalid AccountID. Please check your AccountID');
            }
            else {
                return true;
            }
        }
    },
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default,
        pageVisit: pageVisit_1.default,
        syncAudience: syncAudience_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map