"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addSolutionResourceUrlToAssets = addSolutionResourceUrlToAssets;
const get_portal_api_url_1 = require("../urls/get-portal-api-url");
/**
 * Add a url property to the entries in the assets hash
 * @param {IModelTemplate} template
 * @param {IHubRequestOptions} hubRequestOptions
 */
function addSolutionResourceUrlToAssets(template, hubRequestOptions) {
    let assets = template.assets ||
        /* istanbul ignore next -- @preserve */
        template.resources ||
        /* istanbul ignore next -- @preserve */
        [];
    if (template.bundleItemId) {
        const portalRestUrl = (0, get_portal_api_url_1.getPortalApiUrl)(hubRequestOptions.portalSelf);
        // the resources are stored on the solution item, and that Id is attached
        // into the template as .bundleItemId
        // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
        const solutionItemUrl = `${portalRestUrl}/content/items/${template.bundleItemId}`;
        // the resources on the solution are prefixed with the item id of the item the
        // template was created from, which is stored as .itemId
        const prefix = template.itemId;
        // map over the resources and convert them into assets
        assets = assets.map((asset) => {
            // we fetch the resource from .url property
            // and we upload it using the .name property
            return {
                name: asset.name,
                type: asset.type || "resource",
                url: `${solutionItemUrl}/resources/${prefix}-${asset.name}`,
            };
        });
    }
    return assets;
}
//# sourceMappingURL=add-solution-resource-url-to-assets.js.map