import { BlockType, } from "@superblocksteam/shared";
const makeGetSet = (val, propertyKey) => {
    return [
        val[propertyKey],
        (newVal) => {
            val[propertyKey] = newVal;
        },
    ];
};
/*
  Only return the properties that could contain bindings or code
*/
export function* getSetControlBlockExpressions(block) {
    const { config, type } = block;
    switch (type) {
        case BlockType.BREAK: {
            const controlConfig = config;
            yield makeGetSet(controlConfig, "condition");
            return;
        }
        case BlockType.THROW: {
            const controlConfig = config;
            yield makeGetSet(controlConfig, "error");
            return;
        }
        case BlockType.RETURN: {
            const controlConfig = config;
            yield makeGetSet(controlConfig, "data");
            return;
        }
        case BlockType.WAIT: {
            const controlConfig = config;
            yield makeGetSet(controlConfig, "condition");
            return;
        }
        case BlockType.PARALLEL: {
            const controlConfig = config;
            if (controlConfig.dynamic) {
                yield makeGetSet(controlConfig.dynamic, "paths");
            }
            return;
        }
        case BlockType.CONDITION: {
            const controlConfig = config;
            if (controlConfig.if) {
                yield makeGetSet(controlConfig.if, "condition");
            }
            for (const cond of controlConfig.elseIf ?? []) {
                yield makeGetSet(cond, "condition");
            }
            return;
        }
        case BlockType.LOOP: {
            const controlConfig = config;
            yield makeGetSet(controlConfig, "range");
            return;
        }
        case BlockType.TRY_CATCH: {
            return;
        }
        case BlockType.VARIABLES: {
            const controlConfig = config;
            for (const variable of controlConfig.items) {
                if (variable.value) {
                    yield makeGetSet(variable, "value");
                }
            }
            return;
        }
        case BlockType.SEND: {
            const controlConfig = config;
            yield makeGetSet(controlConfig, "message");
            return;
        }
        case BlockType.STREAM: {
            return;
        }
        default: {
            const exhaustiveCheck = type;
            throw new Error(`Unhandled type: ${exhaustiveCheck}`);
        }
    }
}
// Return a list of all the expressions in the control block - e.g. loop range.
export const getControlBlockExpressions = (block) => {
    return Array.from(getSetControlBlockExpressions(block)).map(([expr]) => expr);
};
//# sourceMappingURL=extract-control-block-identifiers.js.map