"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEventName = exports.isDefined = exports.getUserIdentifier = void 0;
const actions_core_1 = require("@segment/actions-core");
const getUserIdentifier = ({ identity, anonymous_id }) => {
    if (identity && (0, exports.isDefined)(identity)) {
        return {
            identity
        };
    }
    if (anonymous_id && (0, exports.isDefined)(anonymous_id)) {
        return {
            anonymous_id
        };
    }
    throw new actions_core_1.IntegrationError('Either identity or anonymous id are required.', 'MISSING_REQUIRED_FIELD', 400);
};
exports.getUserIdentifier = getUserIdentifier;
const isDefined = (value) => {
    if (typeof value === 'object') {
        return !!value && Object.keys(value).length !== 0;
    }
    return !(value === undefined || value === null || value === '' || value === 0 || value === '0');
};
exports.isDefined = isDefined;
const getEventName = (payload) => {
    let eventName;
    switch (payload.type) {
        case 'track':
            eventName = payload.event;
            break;
        case 'page':
            eventName = 'Page viewed';
            break;
        case 'screen':
            eventName = 'Screen viewed';
            break;
        default:
            eventName = 'track';
            break;
    }
    if (!eventName) {
        return 'track';
    }
    return eventName;
};
exports.getEventName = getEventName;
//# sourceMappingURL=heapUtils.js.map