"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 upsertContactProfile_1 = __importDefault(require("./upsertContactProfile"));
const ortto_client_1 = __importDefault(require("./ortto-client"));
const trackActivity_1 = __importDefault(require("./trackActivity"));
const destination = {
    name: 'Ortto (Actions)',
    slug: 'actions-ortto',
    mode: 'cloud',
    description: 'Send customer data from Segment to Ortto in real time to power campaigns, trigger journeys, and manage audiences with greater flexibility and control.',
    authentication: {
        scheme: 'custom',
        fields: {
            api_key: {
                label: 'API Key',
                description: 'Ortto API key',
                type: 'password',
                required: true
            }
        },
        testAuthentication: async (request, { settings }) => {
            const client = new ortto_client_1.default(request);
            return await client.testAuth(settings);
        }
    },
    extendRequest({ settings }) {
        if (process?.env?.ORTTO_API_KEY) {
            settings.api_key = process?.env?.ORTTO_API_KEY;
        }
        return {
            headers: {
                Authorization: `Bearer ${settings.api_key}`
            }
        };
    },
    presets: [
        {
            name: upsertContactProfile_1.default.title,
            subscribe: 'type = "identify"',
            partnerAction: 'upsertContactProfile',
            mapping: (0, actions_core_1.defaultValues)(upsertContactProfile_1.default.fields),
            type: 'automatic'
        },
        {
            name: trackActivity_1.default.title,
            subscribe: 'type = "track"',
            partnerAction: 'trackActivity',
            mapping: (0, actions_core_1.defaultValues)(trackActivity_1.default.fields),
            type: 'automatic'
        }
    ],
    actions: {
        upsertContactProfile: upsertContactProfile_1.default,
        trackActivity: trackActivity_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map