"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mapValues_1 = __importDefault(require("lodash/mapValues"));
const action = {
    title: 'Send Asset Data',
    description: 'Send Asset data into 1PlusX',
    fields: {
        asset_uri: {
            label: 'Asset ID',
            description: "The asset's unique identifier. Please make sure to map only the fields where values don't include space character",
            type: 'string',
            required: true,
            default: {
                '@template': 'NAMESPACE:asset_uri'
            }
        },
        ope_title: {
            label: 'Asset Title',
            description: 'User friendly description of the asset in the UI',
            type: 'string',
            required: false,
            default: {
                '@path': '$.properties.title'
            }
        },
        ope_content: {
            label: 'Asset Content',
            description: 'Textual content of the asset processing using NLP alogrithms',
            type: 'string',
            required: false,
            default: {
                '@path': '$.properties.content'
            }
        },
        custom_fields: {
            label: 'Custom Fields',
            description: 'Custom fields to include with the event',
            type: 'object'
        }
    },
    perform: (request, { settings, payload }) => {
        const { custom_fields, asset_uri, ...cleanPayload } = payload;
        const cleanProps = (0, mapValues_1.default)(custom_fields, function (value) {
            if (typeof value === 'object' && !(value instanceof Array) && !(value instanceof Date))
                return;
            else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
                return value;
            else if (value instanceof Array)
                return value;
            else
                return JSON.stringify(value);
        });
        const encoded_asset_uri = encodeURIComponent(payload.asset_uri);
        const endpoint = `https://${settings.client_id}.assets.tagger.opecloud.com/v2/native/asset/${encoded_asset_uri}`;
        return request(endpoint, {
            method: 'put',
            json: {
                ...cleanPayload,
                ...cleanProps
            }
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map