"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateVersionMetadata = updateVersionMetadata;
const merge_objects_1 = require("../objects/merge-objects");
const object_to_json_blob_1 = require("../resources/object-to-json-blob");
const getPrefix_1 = require("./_internal/getPrefix");
const constants_1 = require("./_internal/constants");
const getVersion_1 = require("./getVersion");
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
/**
 * Updates the specified version's metadata
 * @param id
 * @param versionMetadata
 * @param owner
 * @param requestOptions
 * @returns
 */
async function updateVersionMetadata(id, versionMetadata, owner, requestOptions) {
    const prefix = (0, getPrefix_1.getPrefix)(versionMetadata.id);
    const properties = (0, merge_objects_1.mergeObjects)(versionMetadata, {}, constants_1.VERSION_RESOURCE_PROPERTIES);
    // fetch the whole version so we can update it
    const version = await (0, getVersion_1.getVersion)(id, versionMetadata.id, requestOptions);
    // apply the metadata to the version
    (0, merge_objects_1.mergeObjects)(versionMetadata, version, constants_1.VERSION_RESOURCE_PROPERTIES);
    const versionBlob = (0, object_to_json_blob_1.objectToJsonBlob)(version);
    await (0, arcgis_rest_portal_1.updateItemResource)(Object.assign(Object.assign({}, requestOptions), { id, name: constants_1.VERSION_RESOURCE_NAME, owner, params: { properties }, prefix, resource: versionBlob }));
    return versionMetadata;
}
//# sourceMappingURL=updateVersionMetadata.js.map