"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertHubGroupToGroup = convertHubGroupToGroup;
const PropertyMapper_1 = require("../../core/_internal/PropertyMapper");
const getPropertyMap_1 = require("./getPropertyMap");
/**
 * Convert a Hub Group to an IGroup
 * @param hubGroup
 */
function convertHubGroupToGroup(hubGroup) {
    // take the _join props and map them to isInvitationOnly and autoJoin
    switch (hubGroup._join) {
        case "invite":
            hubGroup.isInvitationOnly = true;
            hubGroup.autoJoin = false;
            break;
        case "request":
            hubGroup.isInvitationOnly = false;
            hubGroup.autoJoin = false;
            break;
        case "auto":
            hubGroup.isInvitationOnly = false;
            hubGroup.autoJoin = true;
            break;
    }
    const mapper = new PropertyMapper_1.PropertyMapper((0, getPropertyMap_1.getPropertyMap)());
    const group = mapper.entityToStore(hubGroup, {});
    // convert isSharedUpdate to the updateitemcontrol capability
    if (hubGroup.isSharedUpdate) {
        group.capabilities = "updateitemcontrol";
    }
    // convert the values for membershipAccess back to
    // the ones the API accepts
    if (group.membershipAccess === "organization") {
        group.membershipAccess = "org";
    }
    if (group.membershipAccess === "collaborators") {
        group.membershipAccess = "collaboration";
    }
    // since we are setting null to a prop, we need to
    // send clearEmptyFields: true to the updateGroup call
    if (group.membershipAccess === "anyone") {
        group.membershipAccess = "";
        group._clearEmptyFields = true;
    }
    return group;
}
//# sourceMappingURL=convertHubGroupToGroup.js.map