"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const t1_properties_1 = require("../t1-properties");
const action = {
    title: 'Update customer profile',
    description: 'This updates attributes and audiences for a single customer profile. Create all the required attributes and audiences before using this Action.',
    fields: {
        customerProfileId: { ...t1_properties_1.customerProfileId },
        skipNonExistingAttributes: {
            type: 'boolean',
            label: 'Skip Non-existing Attributes Flag',
            description: 'Indicates whether to skip non-existing attributes. If `Yes`, the non-existing attributes are skipped and a 400 error is not returned. If `No`, a 400 error is returned in case of non-existing attributes.',
            default: false,
            required: false
        },
        deleteAudienceIds: { ...t1_properties_1.deleteAudienceId },
        addAudienceIds: { ...t1_properties_1.addAudienceId },
        runRuleEngine: {
            label: 'Run rule engine',
            description: 'This runs rule engine in Talon.One upon updating customer profile. Set to true to trigger rules.',
            type: 'boolean',
            default: true
        },
        attributes: { ...t1_properties_1.attribute }
    },
    perform: (request, { payload }) => {
        let requestUrl = `https://integration.talon.one/segment/v2/customer_profiles/${payload.customerProfileId}`;
        if (payload.skipNonExistingAttributes) {
            requestUrl += '?skipNonExistingAttributes=true';
        }
        return request(requestUrl, {
            method: 'put',
            json: {
                audiencesChanges: {
                    adds: payload.addAudienceIds,
                    deletes: payload.deleteAudienceIds
                },
                runRuleEngine: payload.runRuleEngine,
                attributes: payload.attributes
            }
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map