namespace AIStudio.Assistants.BeyondFactsLab; /// /// Decides which preparation the BeyondFacts Lab shows after its list changed. /// public static class BflProjectSelection { /// /// Chooses the preparation to show: the one asked for, else the one selected last, else the one changed last. /// /// The preparations, the one changed last first. /// The preparation asked for, e.g., one just created or the one shown so far. /// The preparation the person selected last, from an earlier session. /// The preparation to show, or null when there is none. public static BflProjectEntry? Choose(IReadOnlyList projects, Guid? preferredId, Guid? lastSelectedId) { foreach (var candidateId in new[] { preferredId, lastSelectedId }) { if (candidateId is null) continue; var candidate = projects.FirstOrDefault(project => project.ProjectId == candidateId); if (candidate is not null) return candidate; } return projects.Count > 0 ? projects[0] : null; } }