"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const client_1 = require("../client");
const functions_1 = require("../functions");
const action = {
    title: 'Page Views',
    description: 'Send page view and screen view events to Topsort',
    defaultSubscription: 'type = "page" or type = "screen"',
    fields: {
        id: {
            label: 'Event ID',
            description: 'Unique ID generated by the client to suppress duplicate events. The length should not exceed 128 characters.',
            type: 'string',
            required: true,
            default: {
                '@path': '$.messageId'
            }
        },
        occurredAt: {
            label: 'Occurred At',
            description: 'Timestamp that the event happened at.',
            type: 'datetime',
            required: true,
            default: {
                '@path': '$.timestamp'
            }
        },
        opaqueUserId: {
            label: 'Opaque User ID',
            description: 'Identifier for tracking users regardless of sign-in status. The length should not exceed 128 characters.',
            type: 'string',
            required: true,
            default: {
                '@path': '$.anonymousId'
            }
        },
        page: {
            label: 'Page',
            description: 'Page information for the impression.',
            type: 'object',
            required: true,
            properties: {
                type: {
                    label: 'Page Type',
                    description: 'Type of page.',
                    type: 'string',
                    required: true
                },
                pageId: {
                    label: 'Page ID',
                    description: 'Identifies the page.',
                    type: 'string',
                    required: true
                },
                value: {
                    label: 'Page Value',
                    description: 'Detail of the page, depending on the type.',
                    type: 'string',
                    required: false
                }
            },
            default: {
                '@merge': {
                    objects: [
                        {
                            value: { '@path': '$.context.page.title' }
                        },
                        { '@path': '$.properties.page' }
                    ],
                    direction: 'right'
                }
            }
        },
        deviceType: {
            label: 'Device Type',
            description: 'The device the user is on.',
            type: 'string',
            required: false,
            default: {
                '@path': '$.context.device.type'
            }
        },
        channel: {
            label: 'Channel',
            description: 'The channel where the event occurred.',
            type: 'string',
            required: false,
            default: {
                '@path': '$.properties.channel'
            }
        }
    },
    perform: (request, { payload, settings }) => {
        const client = new client_1.TopsortAPIClient(request, settings);
        payload.deviceType = (0, functions_1.NormalizeDeviceType)(payload.deviceType);
        return client.sendEvent({
            pageviews: [payload]
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map