"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const recombeeApiClient_1 = require("../recombeeApiClient");
const commonFields_1 = require("../commonFields");
const action = {
    title: 'Add Detail View',
    description: 'Adds a detail view of the given item made by the given user.',
    fields: {
        userId: {
            label: 'User ID',
            description: 'The ID of the user who viewed the item.',
            type: 'string',
            required: true,
            default: {
                '@if': {
                    exists: { '@path': '$.userId' },
                    then: { '@path': '$.userId' },
                    else: { '@path': '$.anonymousId' }
                }
            }
        },
        itemId: {
            label: 'Item ID',
            description: 'The viewed item.',
            type: 'string',
            required: true,
            default: {
                '@if': {
                    exists: { '@path': '$.properties.product_id' },
                    then: { '@path': '$.properties.product_id' },
                    else: { '@path': '$.properties.asset_id' }
                }
            }
        },
        timestamp: {
            label: 'Timestamp',
            description: 'The UTC timestamp of when the view occurred.',
            type: 'string',
            required: false,
            default: { '@path': '$.timestamp' }
        },
        duration: {
            label: 'Duration',
            description: 'The duration of the view in seconds.',
            type: 'integer',
            required: false
        },
        ...(0, commonFields_1.interactionFields)('view')
    },
    perform: async (request, data) => {
        const client = new recombeeApiClient_1.RecombeeApiClient(data.settings, request);
        await client.send(new recombeeApiClient_1.AddDetailView(data.payload));
    },
    performBatch: async (request, data) => {
        const client = new recombeeApiClient_1.RecombeeApiClient(data.settings, request);
        await client.send(new recombeeApiClient_1.Batch(data.payload.map((payload) => new recombeeApiClient_1.AddDetailView(payload))));
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map