"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validate = exports.VALIDATE_RESULT = void 0;
var VALIDATE_RESULT;
(function (VALIDATE_RESULT) {
    VALIDATE_RESULT[VALIDATE_RESULT["SUCCESS"] = 0] = "SUCCESS";
    VALIDATE_RESULT[VALIDATE_RESULT["INVALID_OP"] = 1] = "INVALID_OP";
    VALIDATE_RESULT[VALIDATE_RESULT["INVALID_COMPONENT"] = 2] = "INVALID_COMPONENT";
    VALIDATE_RESULT[VALIDATE_RESULT["ADJACENT_SAME_TYPE"] = 3] = "ADJACENT_SAME_TYPE";
    VALIDATE_RESULT[VALIDATE_RESULT["NO_TRAILING_RETAIN"] = 4] = "NO_TRAILING_RETAIN";
})(VALIDATE_RESULT || (exports.VALIDATE_RESULT = VALIDATE_RESULT = {}));
const validate = (op) => {
    if (!(op instanceof Array))
        return VALIDATE_RESULT.INVALID_OP;
    if (op.length === 0)
        return VALIDATE_RESULT.INVALID_OP;
    let last;
    for (let i = 0; i < op.length; i++) {
        const component = op[i];
        if (typeof component === 'number') {
            if (!component)
                return VALIDATE_RESULT.INVALID_COMPONENT;
            if (component !== Math.round(component))
                return VALIDATE_RESULT.INVALID_COMPONENT;
            if (component > 0) {
                const lastComponentIsRetain = typeof last === 'number' && last > 0;
                if (lastComponentIsRetain)
                    return VALIDATE_RESULT.ADJACENT_SAME_TYPE;
            }
            else {
                const lastComponentIsDelete = typeof last === 'number' && last < 0;
                if (lastComponentIsDelete)
                    return VALIDATE_RESULT.ADJACENT_SAME_TYPE;
            }
        }
        else if (component instanceof Uint8Array) {
            if (!component.length)
                return VALIDATE_RESULT.INVALID_COMPONENT;
            const lastComponentIsInsert = last instanceof Uint8Array;
            if (lastComponentIsInsert)
                return VALIDATE_RESULT.ADJACENT_SAME_TYPE;
        }
        else {
            return VALIDATE_RESULT.INVALID_COMPONENT;
        }
        last = component;
    }
    const isLastRetain = typeof last === 'number' && last > 0;
    if (isLastRetain)
        return VALIDATE_RESULT.NO_TRAILING_RETAIN;
    return VALIDATE_RESULT.SUCCESS;
};
exports.validate = validate;
//# sourceMappingURL=validate.js.map