export function resolveConfiguredTaskListOptions(cfg) {
    const tasks = getOwnEntry(cfg, "tasks");
    if (tasks === undefined) {
        throw new Error("Maestro workflow is missing tasks config.");
    }
    const tasksRecord = tasks;
    const taskType = getOwnEntry(tasksRecord, "type");
    const taskProject = getOwnEntry(tasksRecord, "project");
    if (!hasOwnEntry(tasksRecord, "path") &&
        !(taskType === "gh-issues" && taskProject === undefined)) {
        return tasks;
    }
    return {
        ...tasks,
        stateMachine: {
            initial: cfg.stateOrder[0],
            states: cfg.stateOrder,
            events: deriveStateEvents(cfg.stateOrder, cfg.terminalStateNames)
        }
    };
}
function hasOwnEntry(record, key) {
    return Object.prototype.hasOwnProperty.call(record, key);
}
function getOwnEntry(record, key) {
    return hasOwnEntry(record, key) ? record[key] : undefined;
}
function deriveStateEvents(stateOrder, terminalStateNames) {
    const terminalStates = new Set(terminalStateNames);
    const activeStates = stateOrder.filter((state) => !terminalStates.has(state));
    return Object.fromEntries(stateOrder.map((state) => [
        state,
        {
            from: activeStates.filter((source) => source !== state),
            to: state
        }
    ]));
}
