import { pickNonBaseParams } from '../../api-client-utils.js';
export const baseInsightUrl = (req, path) => `${req.url}/rest/organizations/${req.organizationId}/insight/v1/configs/${req.insightId}${path ?? ''}`;
export const baseInsightUserActionsUrl = (req) => `${req.url}/rest/organizations/${req.organizationId}/machinelearning/user/actions`;
export const baseInsightRequest = (req, method, contentType, path) => {
    validateInsightRequestParams(req);
    const baseUrl = baseInsightUrl(req, path);
    return {
        accessToken: req.accessToken,
        method,
        contentType,
        url: baseUrl,
        origin: 'insightApiFetch',
    };
};
export const baseInsightUserActionRequest = (req, method, contentType) => {
    validateInsightUserActionRequestParams(req);
    const baseUrl = baseInsightUserActionsUrl(req);
    return {
        accessToken: req.accessToken,
        method,
        contentType,
        url: baseUrl,
        origin: 'insightApiFetch',
    };
};
export const pickNonInsightParams = (req) => {
    const { insightId, ...nonInsightParams } = pickNonBaseParams(req);
    return nonInsightParams;
};
const validateConfigParams = (req) => {
    if (!req.url) {
        throw new Error("The 'url' attribute must contain a valid platform URL.");
    }
    if (!req.organizationId) {
        throw new Error("The 'organizationId' attribute must contain a valid organization ID.");
    }
    if (!req.accessToken) {
        throw new Error("The 'accessToken' attribute must contain a valid platform access token.");
    }
};
const validateInsightRequestParams = (req) => {
    validateConfigParams(req);
    if (!req.insightId) {
        throw new Error("The 'insightId' attribute must contain a valid Insight Panel configuration ID.");
    }
};
const validateInsightUserActionRequestParams = (req) => {
    validateConfigParams(req);
    if (!req.userId) {
        throw new Error("The 'userId' attribute must contain a valid user ID.");
    }
};
