"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockType = exports.VariableMode = exports.VariableType = exports.LOOP_TYPE = exports.WAIT_STR = exports.WAIT_NUM = void 0;
exports.convertBlock = convertBlock;
exports.isStepBlock = isStepBlock;
exports.isControlBlock = isControlBlock;
exports.getPluginType = getPluginType;
var WAIT_NUM;
(function (WAIT_NUM) {
    WAIT_NUM[WAIT_NUM["WAIT_UNSPECIFIED"] = 0] = "WAIT_UNSPECIFIED";
    WAIT_NUM[WAIT_NUM["WAIT_ALL"] = 1] = "WAIT_ALL";
    WAIT_NUM[WAIT_NUM["WAIT_NONE"] = 2] = "WAIT_NONE";
})(WAIT_NUM || (exports.WAIT_NUM = WAIT_NUM = {}));
var WAIT_STR;
(function (WAIT_STR) {
    WAIT_STR["WAIT_UNSPECIFIED"] = "WAIT_UNSPECIFIED";
    WAIT_STR["WAIT_ALL"] = "WAIT_ALL";
    WAIT_STR["WAIT_NONE"] = "WAIT_NONE";
})(WAIT_STR || (exports.WAIT_STR = WAIT_STR = {}));
// loop
var LOOP_TYPE;
(function (LOOP_TYPE) {
    LOOP_TYPE["UNSPECIFIED"] = "TYPE_UNSPECIFIED";
    LOOP_TYPE["FOR"] = "TYPE_FOR";
    LOOP_TYPE["FOREACH"] = "TYPE_FOREACH";
    LOOP_TYPE["WHILE"] = "TYPE_WHILE";
})(LOOP_TYPE || (exports.LOOP_TYPE = LOOP_TYPE = {}));
// variables
var VariableType;
(function (VariableType) {
    VariableType["UNSPECIFIED"] = "TYPE_UNSPECIFIED";
    VariableType["SIMPLE"] = "TYPE_SIMPLE";
    VariableType["ADVANCED"] = "TYPE_ADVANCED";
})(VariableType || (exports.VariableType = VariableType = {}));
var VariableMode;
(function (VariableMode) {
    VariableMode["UNSPECIFIED"] = "MODE_UNSPECIFIED";
    VariableMode["READ"] = "MODE_READ";
    VariableMode["READWRITE"] = "MODE_READWRITE";
})(VariableMode || (exports.VariableMode = VariableMode = {}));
const ALL_BLOCK_TYPES = [
    'break',
    'return',
    'wait',
    'throw',
    'parallel',
    'conditional',
    'loop',
    'tryCatch',
    'step',
    'variables',
    'send',
    'stream'
];
exports.BlockType = {
    CONDITION: 'CONDITION',
    LOOP: 'LOOP',
    PARALLEL: 'PARALLEL',
    TRY_CATCH: 'TRY_CATCH',
    VARIABLES: 'VARIABLES',
    RETURN: 'RETURN',
    BREAK: 'BREAK',
    WAIT: 'WAIT',
    THROW: 'THROW',
    STEP: 'STEP',
    SEND: 'SEND',
    STREAM: 'STREAM'
};
function getBlockType(type) {
    switch (type) {
        case 'break':
            return exports.BlockType.BREAK;
        case 'return':
            return exports.BlockType.RETURN;
        case 'wait':
            return exports.BlockType.WAIT;
        case 'throw':
            return exports.BlockType.THROW;
        case 'parallel':
            return exports.BlockType.PARALLEL;
        case 'conditional':
            return exports.BlockType.CONDITION;
        case 'loop':
            return exports.BlockType.LOOP;
        case 'tryCatch':
            return exports.BlockType.TRY_CATCH;
        case 'variables':
            return exports.BlockType.VARIABLES;
        case 'send':
            return exports.BlockType.SEND;
        case 'stream':
            return exports.BlockType.STREAM;
        case 'step':
            return exports.BlockType.STEP;
        default: {
            const exhaustiveCheck = type;
            throw new Error(`Unhandled block type: ${exhaustiveCheck}`);
        }
    }
}
function convertBlock(backendBlock) {
    for (const blockType of ALL_BLOCK_TYPES) {
        if (blockType in backendBlock) {
            const config = backendBlock[blockType];
            if (config != null) {
                return {
                    type: getBlockType(blockType),
                    config
                };
            }
        }
    }
    return null;
}
function isStepBlock(block) {
    return block.type === exports.BlockType.STEP;
}
function isControlBlock(block) {
    return !isStepBlock(block);
}
function getPluginType(block) {
    if (isStepBlock(block)) {
        return block.config.integration ?? null;
    }
    return null;
}
//# sourceMappingURL=control-flow.js.map