"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 util_1 = require("./util");
const identifyPlayer_1 = __importDefault(require("./identifyPlayer"));
const trackOrder_1 = __importDefault(require("./trackOrder"));
const destination = {
    name: 'Gameball (Actions)',
    slug: 'actions-gameball',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'API Key',
                description: 'Go to [help center](https://help.gameball.co/en/articles/3467114-get-your-account-integration-details-api-key-and-transaction-key) to learn how to find your API Key.',
                type: 'password',
                required: true
            },
            secretKey: {
                label: 'Secret Key',
                description: 'Go to [help center](https://help.gameball.co/en/articles/3467114-get-your-account-integration-details-api-key-and-transaction-key) to learn how to find your API Key.',
                type: 'password',
                required: true
            }
        },
        testAuthentication: (request, { settings }) => {
            const endpoint = `${util_1.endpoints.baseAuthUrl}${util_1.endpoints.testAuthentication}`;
            return (0, util_1.sendRequest)(request, endpoint, settings, {
                apiKey: settings.apiKey,
                secretKey: settings.secretKey
            });
        }
    },
    presets: [
        {
            name: 'Track Events',
            subscribe: 'type = "track" and event != "Order Completed"',
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Track Orders',
            subscribe: 'type = "track" and event = "Order Completed"',
            partnerAction: 'trackOrder',
            mapping: (0, actions_core_1.defaultValues)(trackOrder_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Create Or Update Players',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyPlayer',
            mapping: (0, actions_core_1.defaultValues)(identifyPlayer_1.default.fields),
            type: 'automatic'
        }
    ],
    actions: {
        trackEvent: trackEvent_1.default,
        identifyPlayer: identifyPlayer_1.default,
        trackOrder: trackOrder_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map