"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const url_provider_1 = require("../url-provider");
const action = {
    title: 'Add custom event',
    description: 'Send the Track, Page or Screen event that will be saved as a [custom event](https://docs.voucherify.io/reference/the-custom-event-object) in Voucherify.',
    defaultSubscription: 'type = "track" or type = "page" or type = "screen"',
    fields: {
        customer: {
            label: 'Customer Object',
            required: true,
            description: 'This is an object containing information about the [customer](https://docs.voucherify.io/reference/the-customer-object).',
            type: 'object',
            properties: {
                source_id: {
                    label: 'Source ID',
                    type: 'string',
                    required: true,
                    description: 'The `source_id` which identifies the [customer](https://docs.voucherify.io/reference/the-customer-object) in Voucherify.'
                },
                email: {
                    label: 'Email',
                    type: 'string',
                    description: 'The email that identifies the [customer](https://docs.voucherify.io/reference/the-customer-object) in Voucherify.'
                }
            },
            default: {
                source_id: { '@path': '$.userId' },
                email: {
                    '@if': {
                        exists: { '@path': '$.properties.email' },
                        then: { '@path': '$.properties.email' },
                        else: { '@path': '$.context.traits.email' }
                    }
                }
            }
        },
        referral: {
            label: 'Referral Object',
            description: 'If a conversion event for a referral program is set to a [custom event](https://docs.voucherify.io/reference/custom-event-object), then you need to send the referral code in the payload to make a record of the conversion event.',
            type: 'object',
            properties: {
                code: {
                    label: 'code',
                    type: 'string'
                },
                referrer_id: {
                    label: 'referrer_id',
                    type: 'string'
                }
            },
            default: {
                code: { '@path': '$.properties.referral.code' },
                referrer_id: { '@path': '$.properties.referral.referrer_id' }
            }
        },
        loyalty: {
            label: 'Loyalty Object',
            description: 'If an earning rule in a loyalty program is based on a [custom event](https://docs.voucherify.io/reference/custom-event-object). This objects allows you specify the loyalty card to which the custom event should be attributed to.',
            type: 'object',
            properties: {
                code: {
                    label: 'code',
                    type: 'string'
                }
            },
            default: {
                code: { '@path': '$.properties.loyalty.code' }
            }
        },
        metadata: {
            label: 'Track Event Metadata',
            description: 'The metadata object stores all custom attributes assigned to the [custom event](https://docs.voucherify.io/reference/custom-event-object). A set of key/value pairs that you can attach to an event object. It can be useful for storing additional information about the event in a structured format. Event metadata schema is defined in the Dashboard > Project Settings > Event Schema > Edit particular event > Metadata property definition.',
            type: 'object',
            default: {
                '@path': '$.properties.metadata'
            }
        },
        event: {
            label: 'Event Name',
            description: 'The name of the event that will be saved as a [custom event](https://docs.voucherify.io/reference/the-custom-event-object) in Voucherify.',
            type: 'string',
            default: {
                '@if': {
                    exists: { '@path': '$.event' },
                    then: { '@path': '$.event' },
                    else: { '@path': '$.name' }
                }
            }
        },
        type: {
            label: 'Event Type',
            description: 'Type of the [event](https://segment.com/docs/connections/spec/). For example: identify, track, page, screen or group',
            type: 'string',
            required: true,
            default: {
                '@path': '$.type'
            }
        }
    },
    perform: (request, { settings, payload }) => {
        const voucherifyRequestURL = (0, url_provider_1.getVoucherifyEndpointURL)(settings, 'event');
        return request(voucherifyRequestURL, {
            method: 'post',
            json: payload
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map