"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGroupOp = exports.createInsertToRegisterOp = exports.createInsertFromRegisterOp = exports.createInsertOp = exports.createInsertSegmentOp = exports.createRemoveRangeOp = exports.createAnnotateRangeOp = exports.createAnnotateMarkerOp = void 0;
/**
 * Creates the op for annotating the markers with the provided properties
 * @param marker - The marker to annotate
 * @param props - The properties to annotate the marker with
 * @param combiningOp - Optional. Specifies how to combine values for the property, such as "incr" for increment.
 * @returns The annotate op
 */
function createAnnotateMarkerOp(marker, props, combiningOp) {
    const id = marker.getId();
    if (!id) {
        return undefined;
    }
    return {
        combiningOp,
        props,
        relativePos1: { id, before: true },
        relativePos2: { id },
        type: 2 /* ANNOTATE */,
    };
}
exports.createAnnotateMarkerOp = createAnnotateMarkerOp;
/**
 * Creates the op for annotating the range with the provided properties
 * @param start - The inclusive start postition of the range to annotate
 * @param end - The exclusive end position of the range to annotate
 * @param props - The properties to annotate the range with
 * @param combiningOp - Optional. Specifies how to combine values for the property, such as "incr" for increment.
 * @returns The annotate op
 */
function createAnnotateRangeOp(start, end, props, combiningOp) {
    return {
        combiningOp,
        pos1: start,
        pos2: end,
        props,
        type: 2 /* ANNOTATE */,
    };
}
exports.createAnnotateRangeOp = createAnnotateRangeOp;
/**
 * Creates the op to remove a range and puts the content of the removed range in a register
 * if a register name is provided
 *
 * @param start - The inclusive start of the range to remove
 * @param end - The exclusive end of the range to remove
 * @param register - Optional. The name of the register to store the removed range in
 */
function createRemoveRangeOp(start, end, register) {
    return {
        pos1: start,
        pos2: end,
        register,
        type: 1 /* REMOVE */,
    };
}
exports.createRemoveRangeOp = createRemoveRangeOp;
/**
 *
 * @param pos - The position to insert the segment at
 * @param segment - The segment to insert
 */
function createInsertSegmentOp(pos, segment) {
    return createInsertOp(pos, segment.toJSONObject());
}
exports.createInsertSegmentOp = createInsertSegmentOp;
function createInsertOp(pos, segSpec) {
    return {
        pos1: pos,
        seg: segSpec,
        type: 0 /* INSERT */,
    };
}
exports.createInsertOp = createInsertOp;
/**
 *
 * @param pos - The position to insert the register contents at
 * @param register - The name of the register to insert the value of
 */
function createInsertFromRegisterOp(pos, register) {
    return {
        pos1: pos,
        register,
        type: 0 /* INSERT */,
    };
}
exports.createInsertFromRegisterOp = createInsertFromRegisterOp;
/**
 *
 * @param start - The inclusive start of the range to insert into the register
 * @param end - The exclusive end of the range to insert into the register
 * @param register - The name of the register to insert the range contents into
 */
function createInsertToRegisterOp(start, end, register) {
    return {
        pos1: start,
        pos2: end,
        register,
        type: 0 /* INSERT */,
    };
}
exports.createInsertToRegisterOp = createInsertToRegisterOp;
/**
 *
 * @param ops - The ops to group
 */
function createGroupOp(...ops) {
    return {
        ops,
        type: 3 /* GROUP */,
    };
}
exports.createGroupOp = createGroupOp;
//# sourceMappingURL=opBuilder.js.map