export function readTasksCanonicalAuthority(config) {
    const tasks = config?.tasks;
    const raw = tasks?.canonicalAuthority ?? tasks?.taskStateCanonicalAuthority;
    return raw === "git-event-log" ? "git-event-log" : "sqlite";
}
export function isGitTaskStateCanonicalAuthority(ctx) {
    return readTasksCanonicalAuthority(ctx.effectiveConfig) === "git-event-log";
}
/** Monotonic per-task version used for optimistic concurrency (matches event applier bumps). */
export function taskVersionFromStore(store, taskId) {
    if (!store.getTask(taskId)) {
        return 0;
    }
    let version = 1;
    for (const tr of store.getTransitionLog()) {
        if (tr.taskId === taskId) {
            version += 1;
        }
    }
    for (const m of store.getMutationLog()) {
        if (m.taskId === taskId && m.mutationType === "update-task") {
            version += 1;
        }
    }
    return version;
}
export function expectedTaskVersionsForTaskIds(store, taskIds) {
    const out = {};
    for (const taskId of taskIds) {
        const version = taskVersionFromStore(store, taskId);
        if (version > 0) {
            out[taskId] = version;
        }
    }
    return out;
}
export function readCanonicalPublishQueueMode(config) {
    const tasks = config?.tasks;
    const queue = tasks?.canonicalPublishQueue;
    return queue?.enabled === true;
}
