"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createModel = createModel;
const wrappers_1 = require("../rest/portal/wrappers");
const extent_1 = require("../extent");
const util_1 = require("../util");
const getModel_1 = require("./getModel");
/**
 * Create an item to back and IModel.
 *
 * @param {IModel}
 * @param {IRequestOptions} requestOptions
 * @returns {Promise<IModel>}
 */
async function createModel(model, requestOptions) {
    // const clone = cloneObject(model) as IModel;
    const item = (0, util_1.cloneObject)(model.item);
    item.data = (0, util_1.cloneObject)(model.data);
    // Update extent from bbox to string
    // TODO: remove below logic once rest.js is fixed.
    if (item.extent && typeof item.extent !== "string") {
        // THIS IS A HACK TO WORK AROUND REST.JS BUG
        // and normally should never be done.
        item.extent = (0, extent_1.bboxToString)(item.extent);
    }
    // Create the item
    const createResponse = await (0, wrappers_1.createItem)(Object.assign({ item }, requestOptions));
    // Re-fetch the model and return that so it has all the latest prop values
    return (0, getModel_1.getModel)(createResponse.id, requestOptions);
}
//# sourceMappingURL=createModel.js.map