/**
 * Every variant of `GeneralizedTaskDefinition` declares an optional
 * `context?: { docs?: GeneralizedDocRef[]; ... }`, so structural access
 * narrows correctly without an `as` cast. Returns `undefined` when the
 * task carries no doc refs.
 */
function taskContextDocs(task) {
    return task.context?.docs;
}
/**
 * `GeneralizedDocRef` is a 4-way union — only `SlugDocRef` and `IdDocRef`
 * carry a `slug`. Returns `undefined` for path / perspective refs.
 */
function docSlug(ref) {
    return "slug" in ref ? ref.slug : undefined;
}
export function filterByChangedDocs(tasks, changedDocs) {
    if (!changedDocs || changedDocs.length === 0)
        return [...tasks];
    const wanted = new Set(changedDocs);
    return tasks.filter((task) => {
        const docs = taskContextDocs(task);
        if (!docs || docs.length === 0)
            return false;
        return docs.some((d) => {
            const slug = docSlug(d);
            return slug != null && wanted.has(slug);
        });
    });
}
