"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("../util");
const mapPayload = (payload) => {
    delete payload.metadata?.mobile;
    return {
        events: {
            [payload.name.trim()]: payload.metadata
        },
        playerUniqueId: payload.playerUniqueId.toLowerCase(),
        mobile: payload.mobile?.toLowerCase(),
        email: payload.email?.toLowerCase()
    };
};
const action = {
    title: 'Track Event',
    description: `This action allows you to track and send your players' events to Gameball.`,
    defaultSubscription: 'type = "track"',
    fields: {
        name: {
            label: 'Event Name',
            description: 'The name of the event',
            type: 'string',
            required: true,
            default: {
                '@path': '$.event'
            }
        },
        metadata: {
            label: 'Event Metadata',
            description: 'The event metadata to send to Gameball',
            type: 'object',
            default: {
                '@path': '$.properties'
            }
        },
        ...util_1.playerProperties
    },
    perform: async (request, { payload, settings }) => {
        const endpoint = `${util_1.endpoints.baseApiUrl}${util_1.endpoints.trackEvent}`;
        return await (0, util_1.sendRequest)(request, endpoint, settings, mapPayload(payload));
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map