"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ortto_client_1 = __importDefault(require("./ortto-client"));
const syncAudience_1 = __importDefault(require("./syncAudience"));
const destination = {
    name: 'Ortto (Audiences)',
    slug: 'actions-ortto-audiences',
    mode: 'cloud',
    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}`
            }
        };
    },
    audienceFields: {
        audienceName: {
            label: 'Audience Name',
            description: 'The name of the Audience in Ortto',
            type: 'string',
            required: true
        }
    },
    audienceConfig: {
        mode: {
            type: 'synced',
            full_audience_sync: false
        },
        async createAudience(request, createAudienceInput) {
            const { settings, audienceName } = createAudienceInput;
            const client = new ortto_client_1.default(request);
            const audience = await client.createAudience(settings, audienceName);
            return {
                externalId: audience.id
            };
        },
        async getAudience(request, { settings, externalId }) {
            const client = new ortto_client_1.default(request);
            const audience = await client.getAudience(settings, externalId);
            return {
                externalId: audience.id
            };
        }
    },
    actions: {
        syncAudience: syncAudience_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map