"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 trackEvent_1 = __importDefault(require("./trackEvent"));
const identifyUser_1 = __importDefault(require("./identifyUser"));
const COLLAB_CRM_BASE_URL = 'https://wvjaseexkfrcahmzfxkl.supabase.co/functions/v1';
const destination = {
    name: 'Collab Travel CRM',
    slug: 'actions-collab-travel-crm',
    mode: 'cloud',
    description: 'Sync your customer data, bookings, and leads with Collab Travel CRM - the all-in-one platform for modern travel agencies.',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'API Key',
                description: 'Your Collab Travel CRM webhook secret. Find this in Settings > Integrations > Segment.',
                type: 'password',
                required: true
            }
        },
        testAuthentication: async (request, { settings }) => {
            const response = await request(`${COLLAB_CRM_BASE_URL}/segment-destination`, {
                method: 'POST',
                headers: {
                    Authorization: `Bearer ${settings.apiKey}`,
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    type: 'track',
                    event: '__segment_test__',
                    properties: {
                        test: true
                    }
                })
            });
            return response;
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                Authorization: `Bearer ${settings.apiKey}`,
                'Content-Type': 'application/json'
            }
        };
    },
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default
    },
    presets: [
        {
            name: 'Track Events',
            subscribe: 'type = "track"',
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Identify Users',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: (0, actions_core_1.defaultValues)(identifyUser_1.default.fields),
            type: 'automatic'
        }
    ]
};
exports.default = destination;
//# sourceMappingURL=index.js.map