"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHubChannel = createHubChannel;
exports.updateHubChannel = updateHubChannel;
exports.deleteHubChannel = deleteHubChannel;
const channels_1 = require("../discussions/api/channels/channels");
const transformChannelToEntity_1 = require("./_internal/transformChannelToEntity");
const transformEntityToChannelData_1 = require("./_internal/transformEntityToChannelData");
/**
 * Creates a new Channel from the given IHubChannel object
 * @param entity An IHubChannel object
 * @param context ArcGIS context
 * @returns a promise that resolves an IHubChannel representing the newly created channel
 */
async function createHubChannel(entity, context) {
    const channelData = (0, transformEntityToChannelData_1.transformEntityToChannelData)(entity);
    const createdChannel = await (0, channels_1.createChannelV2)(Object.assign({ data: channelData }, context.hubRequestOptions));
    return (0, transformChannelToEntity_1.transformChannelToEntity)(createdChannel, context.currentUser);
}
/**
 * Updates an existing Channel from the given IHubChannel object
 * @param entity An IHubChannel object
 * @param context ArcGIS context
 * @returns a promise that resolves an IHubChannel representing the updated channel
 */
async function updateHubChannel(entity, context) {
    const updatedChannelData = (0, transformEntityToChannelData_1.transformEntityToChannelData)(entity);
    const updatedChannel = await (0, channels_1.updateChannelV2)(Object.assign({ channelId: entity.id, data: updatedChannelData }, context.hubRequestOptions));
    return (0, transformChannelToEntity_1.transformChannelToEntity)(updatedChannel, context.currentUser);
}
/**
 * Updates an existing Channel from the given IHubChannel object
 * @param channelId The ID of the channel to delete
 * @param context ArcGIS context
 * @returns a promise
 */
async function deleteHubChannel(channelId, context) {
    await (0, channels_1.removeChannelV2)(Object.assign({ channelId }, context.hubRequestOptions));
}
//# sourceMappingURL=edit.js.map