using Core.Entities;

namespace Core.Calculation;

public class DataProcessing
{
	public static EventStudentPicks[] GetEventStudentPicks(IList<CompetitiveEvent> events, IList<Student> students)
	{
		return
			students.SelectMany(
					student => student.RankedEventPicks.Select((e, i) => (e, student, i + 1)))
				.OrderBy(tuple => tuple.Item3)
					.ThenByDescending(tuple => tuple.student.Grade + tuple.student.TsaYear)
				.GroupBy(tuple => tuple.e)
				.OrderBy(tuples => tuples.Key.Name)
				.Select(tuples =>
					new EventStudentPicks(tuples.Key, tuples.Select(tuple => Tuple.Create(tuple.student, tuple.Item3)).ToList())
				).ToArray();
	}
}