"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const pick_1 = __importDefault(require("lodash/pick"));
const utils_1 = require("../utils");
const common_definitions_1 = require("../common-definitions");
const action = {
    title: 'Tag User',
    description: 'Add a tag to a user in Encharge.',
    fields: {
        tag: {
            type: 'string',
            required: true,
            description: 'The tags to add, separated by commas.',
            label: 'Tag',
            default: { '@path': '$.traits.tag' }
        },
        ...(0, pick_1.default)(common_definitions_1.commonFields, ['email', 'userId', 'segmentAnonymousId'])
    },
    perform: (request, data) => {
        if (!data.payload.email && !data.payload.userId && !data.payload.segmentAnonymousId) {
            throw new actions_core_1.PayloadValidationError('No user ID, email, or anonymous ID provided.');
        }
        if (!data.payload.tag?.length) {
            throw new actions_core_1.PayloadValidationError('Missing tag.');
        }
        return request(`${utils_1.enchargeRestAPIBase}/v1/tags`, {
            method: 'post',
            json: data.payload
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map