namespace Core.Entities;

public class StudentEventStatistics
{
    public Student Student { get; set; }
    public List<EventDefinition> Events { get; set; } = [];

    public int? TotalLevelOfEffort => Events.Sum(e => e.LevelOfEffort);

    public int EventCount => Events.Count;

    public bool HasRegionalEvent => Events.Any(e => e.RegionalEvent);

    public bool HasOnSiteActivity => Events.Any(e => e.OnSiteActivity);

    public static List<StudentEventStatistics> Generate(ICollection<Team> teams)
    {
        Dictionary<Student, StudentEventStatistics> statistics = [];

        foreach (var team in teams)
        {
            foreach (var student in team.Students)
            {
                if (!statistics.ContainsKey(student))
                    statistics.Add(student, new StudentEventStatistics(){Student = student});
                statistics[student].Events.Add(team.Event);
            }
        }

        return statistics.Values.ToList();
    }
}