"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 receiveEvents_1 = __importDefault(require("./receiveEvents"));
const tablemaintutilities_1 = require("./Utility/tablemaintutilities");
const mod = `
Last-Modified: 06.28.2023 16.15.37
`;
const presets = [
    {
        name: 'Track Calls',
        subscribe: 'type = "track"',
        partnerAction: 'receiveEvents',
        mapping: {
            ...(0, actions_core_1.defaultValues)(receiveEvents_1.default.fields),
            email: {
                '@if': {
                    exists: { '@path': '$.properties.email' },
                    then: { '@path': '$.properties.email' },
                    else: { '@path': '$.context.traits.email' }
                }
            }
        },
        type: 'automatic'
    },
    {
        name: 'Identify Calls',
        subscribe: 'type = "identify"',
        partnerAction: 'receiveEvents',
        mapping: {
            ...(0, actions_core_1.defaultValues)(receiveEvents_1.default.fields),
            email: {
                '@if': {
                    exists: { '@path': '$.traits.email' },
                    then: { '@path': '$.traits.email' },
                    else: { '@path': '$.context.traits.email' }
                }
            }
        },
        type: 'automatic'
    }
];
const destination = {
    name: 'Acoustic Campaign (Actions)',
    slug: 'actions-acoustic-campaign',
    mode: 'cloud',
    authentication: {
        scheme: 'oauth2',
        fields: {
            pod: {
                label: 'Pod',
                description: 'Pod Number for API Endpoint',
                default: '2',
                type: 'string',
                required: true
            },
            region: {
                label: 'Region',
                description: 'Region for API Endpoint, either US, EU, AP, or CA',
                choices: [
                    { label: 'US', value: 'US' },
                    { label: 'EU', value: 'EU' },
                    { label: 'AP', value: 'AP' },
                    { label: 'CA', value: 'CA' }
                ],
                default: 'US',
                type: 'string',
                required: true
            },
            tableName: {
                label: 'Acoustic Segment Table Name',
                description: `The Segment Table Name in Acoustic Campaign Data dialog.`,
                default: 'Segment Events Table Name',
                type: 'string',
                required: true
            },
            tableListId: {
                label: 'Acoustic Segment Table List Id',
                description: 'The Segment Table List Id from the Database-Relational Table dialog in Acoustic Campaign',
                default: '',
                type: 'string',
                required: true
            },
            a_clientId: {
                label: 'Acoustic App Definition ClientId',
                description: 'The Client Id from the App definition dialog in Acoustic Campaign',
                default: '',
                type: 'string',
                required: true
            },
            a_clientSecret: {
                label: 'Acoustic App Definition ClientSecret',
                description: 'The Client Secret from the App definition dialog in Acoustic Campaign',
                default: '',
                type: 'password',
                required: true
            },
            a_refreshToken: {
                label: 'Acoustic App Access Definition RefreshToken',
                description: 'The RefreshToken provided when defining access for the App in Acoustic Campaign',
                default: '',
                type: 'password',
                required: true
            },
            attributesMax: {
                label: 'Properties Max',
                description: 'A safety against mapping too many attributes into the Event, Event will be ignored if number of Event Attributes exceeds this maximum. Note: Before increasing the default max number, consult the Acoustic Destination documentation.',
                default: 15,
                type: 'number',
                required: false
            },
            version: {
                label: `Version:`,
                description: `${mod}`,
                default: `Version 3.1   (nodeJS: ${process.version})`,
                type: 'string',
                required: false
            }
        },
        refreshAccessToken: async (request, { settings }) => {
            return await (0, tablemaintutilities_1.getAccessToken)(request, settings);
        }
    },
    presets,
    actions: {
        receiveEvents: receiveEvents_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map