using Core.Entities; namespace Core.Models; public class PartialTeam : Team { public IList OmittedStudents { get; set; } = null!; public override Team CloneWithOmittedStudents(IEnumerable studentsToOmit) { var remainingStudents = Students.Where(s => !studentsToOmit.Contains(s)).ToList(); var omittedStudents = OmittedStudents.Union(Students.Where(studentsToOmit.Contains)).Distinct().ToList(); return new PartialTeam{Identifier = Identifier, Event = Event, Students = remainingStudents, OmittedStudents = omittedStudents }; } /// /// Creates PartialTeam instances from teams with excluded students. /// Aggregates exclusions across all time slots for each team. /// /// The teams to process /// Dictionary of excluded students: key is (teamId, timeSlotIndex, studentId), value is true if excluded /// Array of teams, with PartialTeam instances for teams with exclusions public static Team[] CreatePartialTeamsFromExclusions( IEnumerable teams, Dictionary<(int teamId, int timeSlotIndex, int studentId), bool> excludedStudents) { return teams.Select(team => { // Find all students excluded for this team across all time slots var excludedStudentIds = excludedStudents.Keys .Where(k => k.teamId == team.Id && excludedStudents[k]) .Select(k => k.studentId) .Distinct() .ToHashSet(); if (excludedStudentIds.Count == 0) return team; var excludedStudentsList = team.Students.Where(s => excludedStudentIds.Contains(s.Id)).ToList(); if (excludedStudentsList.Count == 0) return team; // Create PartialTeam with excluded students return team.CloneWithOmittedStudents(excludedStudentsList); }).ToArray(); } }