import { getEventBus } from '../core/container.js';
import { prisma } from '../utils/index.js';
export async function emitTeamRunInvalidated(input, eventBus = getEventBus()) {
    const payload = {
        teamRunId: input.teamRunId,
        taskId: input.taskId,
        projectId: input.projectId,
        scopes: input.scopes,
        reason: input.reason,
    };
    if (!payload.taskId || !payload.projectId) {
        const teamRun = await prisma.teamRun.findUnique({
            where: { id: input.teamRunId },
            select: {
                taskId: true,
                task: { select: { projectId: true } },
            },
        });
        if (!teamRun) {
            return;
        }
        payload.taskId ??= teamRun.taskId;
        payload.projectId ??= teamRun.task.projectId;
    }
    eventBus.emit('team-run:invalidated', payload);
}
//# sourceMappingURL=team-run-events.js.map