"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const recombeeApiClient_1 = require("../recombeeApiClient");
const commonFields_1 = require("../commonFields");
const action = {
    title: 'Add Rating',
    description: 'Adds a rating of the given item made by the given user.',
    fields: {
        userId: {
            label: 'User ID',
            description: 'The ID of the user who submitted the rating.',
            type: 'string',
            required: true,
            default: {
                '@if': {
                    exists: { '@path': '$.userId' },
                    then: { '@path': '$.userId' },
                    else: { '@path': '$.anonymousId' }
                }
            }
        },
        itemId: {
            label: 'Item ID',
            description: 'The rated 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 rating occurred.',
            type: 'string',
            required: false,
            default: { '@path': '$.timestamp' }
        },
        rating: {
            label: 'Rating',
            description: 'The rating of the item rescaled to interval [-1.0,1.0], where -1.0 means the worst rating possible, 0.0 means neutral, and 1.0 means absolutely positive rating. For example, in the case of 5-star evaluations, rating = (numStars-3)/2 formula may be used for the conversion.',
            type: 'number',
            required: true,
            default: { '@path': '$.properties.rating' }
        },
        ...(0, commonFields_1.interactionFields)('rating')
    },
    perform: async (request, data) => {
        const client = new recombeeApiClient_1.RecombeeApiClient(data.settings, request);
        await client.send(new recombeeApiClient_1.AddRating(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.AddRating(payload))));
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map