"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 track_1 = __importDefault(require("./track"));
const identify_1 = __importDefault(require("./identify"));
const group_1 = __importDefault(require("./group"));
const destination = {
    name: 'Klime',
    slug: 'actions-klime',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            apiEndpoint: {
                label: 'API Endpoint',
                description: 'Klime API endpoint URL',
                type: 'string',
                format: 'uri',
                required: true,
                default: 'https://i.klime.com'
            },
            writeKey: {
                label: 'Write Key',
                description: 'Your Klime write key for authentication',
                type: 'password',
                required: true
            }
        },
        testAuthentication: (request, { settings }) => {
            return request(`${settings.apiEndpoint}/v1/batch`, {
                method: 'post',
                json: { batch: [] }
            });
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                Authorization: `Bearer ${settings.writeKey}`,
                'Content-Type': 'application/json'
            }
        };
    },
    actions: {
        track: track_1.default,
        identify: identify_1.default,
        group: group_1.default
    },
    presets: [
        {
            name: 'Track Event',
            subscribe: 'type = "track"',
            partnerAction: 'track',
            mapping: (0, actions_core_1.defaultValues)(track_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identify',
            mapping: (0, actions_core_1.defaultValues)(identify_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Track Group',
            subscribe: 'type = "group"',
            partnerAction: 'group',
            mapping: (0, actions_core_1.defaultValues)(group_1.default.fields),
            type: 'automatic'
        }
    ]
};
exports.default = destination;
//# sourceMappingURL=index.js.map