using Core.Calculation;
using Core.Entities;
using Tests.Builders;
using Tests.Fixtures;

namespace Tests.Calculation;

[TestFixture]
public class DataProcessingTests
{
	[SetUp]
	public void SetUp()
	{
		BuilderExtensions.ResetAllBuilders();
	}

	[Test]
	public void GetEventStudentRankingsTest()
	{
		// Create test data with explicit rankings
		var flight = EventDefinitionBuilder.Individual("Flight").Build();
		var coding = EventDefinitionBuilder.Individual("Coding").Build();
		var robotics = EventDefinitionBuilder.Team("Robotics", 2, 5).Build();

		var alice = StudentBuilder.Default()
			.WithName("Alice", "Anderson")
			.WithGrade(9)
			.WithRanking(flight, rank: 1)
			.WithRanking(coding, rank: 2)
			.WithRanking(robotics, rank: 3)
			.Build();

		var bob = StudentBuilder.Default()
			.WithName("Bob", "Brown")
			.WithGrade(10)
			.WithRanking(coding, rank: 1)
			.WithRanking(flight, rank: 3)
			.Build();

		// Verify rankings are accessible
		Assert.That(alice.EventRankings, Has.Count.EqualTo(3));
		Assert.That(bob.EventRankings, Has.Count.EqualTo(2));

		// Verify rankings are correctly associated
		var aliceFlightRanking = alice.EventRankings.First(r => r.EventDefinition == flight);
		Assert.That(aliceFlightRanking.Rank, Is.EqualTo(1));
		Assert.That(aliceFlightRanking.Student, Is.EqualTo(alice));

		// Print rankings for verification (matching original test output)
		var allRankings = new[] { alice, bob }
			.SelectMany(s => s.EventRankings)
			.OrderBy(r => r.EventDefinition.Name)
			.ThenBy(r => r.Student.FirstName);

		foreach (var ranking in allRankings)
		{
			Console.WriteLine(ranking.EventDefinition.Name);
			Console.WriteLine($"{ranking.Student.FirstName}: {ranking.Rank}");
		}
	}
}