"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTrackEventParams = exports.getCompanyIdentifyRequestParams = exports.getIdentifyRequestParams = exports.getValidationParams = exports.getDeleteRequestParams = void 0;
const baseURL = 'https://analytex.userpilot.io/';
const getDeleteRequestParams = (settings, userId) => {
    return {
        url: `${validateEndpoint(settings.endpoint)}v1/users`,
        options: {
            method: 'DELETE',
            json: { users: [userId] }
        }
    };
};
exports.getDeleteRequestParams = getDeleteRequestParams;
const getValidationParams = (settings) => {
    return {
        url: `${validateEndpoint(settings.endpoint)}v1/validate`,
        options: {
            method: 'GET'
        }
    };
};
exports.getValidationParams = getValidationParams;
const getIdentifyRequestParams = (settings, payload) => {
    const { traits, userId } = payload;
    return {
        url: `${validateEndpoint(settings.endpoint)}v1/identify`,
        options: {
            method: 'POST',
            json: {
                user_id: userId,
                metadata: traits
            }
        }
    };
};
exports.getIdentifyRequestParams = getIdentifyRequestParams;
const getCompanyIdentifyRequestParams = (settings, payload) => {
    const { traits, groupId } = payload;
    return {
        url: `${validateEndpoint(settings.endpoint)}v1/companies/identify`,
        options: {
            method: 'POST',
            json: {
                company_id: groupId,
                metadata: traits
            }
        }
    };
};
exports.getCompanyIdentifyRequestParams = getCompanyIdentifyRequestParams;
const getTrackEventParams = (settings, payload) => {
    const { userId, name, properties } = payload;
    return {
        url: `${validateEndpoint(settings.endpoint)}v1/track`,
        options: {
            method: 'POST',
            json: {
                user_id: userId,
                event_name: name,
                metadata: properties
            }
        }
    };
};
exports.getTrackEventParams = getTrackEventParams;
const validateEndpoint = (url) => {
    try {
        new URL(url);
        return url;
    }
    catch (e) {
        return baseURL;
    }
};
//# sourceMappingURL=request-utils.js.map