using API.Models.Internal.Altersgruppen;

namespace API.Tests.Mappers;

public class AltersgruppeMapperTests
{
    [Fact]
    public void ToInternalFromIngoing_MapsAllProperties()
    {
        // Arrange
        var ingoing = new AltersGruppeIngoing
        {
            Name = "U14",
            StartingAge = 12,
            EndingAge = 14
        };

        // Act
        var result = ingoing.ToInternalFromIngoing();

        // Assert
        Assert.NotNull(result);
        Assert.Equal("U14", result.Name);
        Assert.Equal(12, result.StartingAge);
        Assert.Equal(14, result.EndingAge);
    }

    [Fact]
    public void ToInternalFromIngoing_GeneratesNewId()
    {
        // Arrange
        var ingoing = new AltersGruppeIngoing
        {
            Name = "U16",
            StartingAge = 14,
            EndingAge = 16
        };

        // Act
        var result = ingoing.ToInternalFromIngoing();

        // Assert
        Assert.NotNull(result.Id);
        Assert.NotEmpty(result.Id);
    }

    [Fact]
    public void ToInternalFromIngoing_GeneratesUniqueIds()
    {
        // Arrange
        var ingoing1 = new AltersGruppeIngoing { Name = "U10", StartingAge = 8, EndingAge = 10 };
        var ingoing2 = new AltersGruppeIngoing { Name = "U12", StartingAge = 10, EndingAge = 12 };

        // Act
        var result1 = ingoing1.ToInternalFromIngoing();
        var result2 = ingoing2.ToInternalFromIngoing();

        // Assert
        Assert.NotEqual(result1.Id, result2.Id);
    }

    [Fact]
    public void ToInternalFromIngoing_WithZeroAges_MapsCorrectly()
    {
        // Arrange
        var ingoing = new AltersGruppeIngoing
        {
            Name = "Beginners",
            StartingAge = 0,
            EndingAge = 0
        };

        // Act
        var result = ingoing.ToInternalFromIngoing();

        // Assert
        Assert.Equal(0, result.StartingAge);
        Assert.Equal(0, result.EndingAge);
    }

    [Fact]
    public void ToInternalFromIngoing_WithNegativeAges_MapsCorrectly()
    {
        // Arrange - testing edge case, though business logic might not allow this
        var ingoing = new AltersGruppeIngoing
        {
            Name = "Invalid",
            StartingAge = -1,
            EndingAge = -5
        };

        // Act
        var result = ingoing.ToInternalFromIngoing();

        // Assert
        Assert.Equal(-1, result.StartingAge);
        Assert.Equal(-5, result.EndingAge);
    }

    [Fact]
    public void ToInternalFromIngoing_WithLargeAges_MapsCorrectly()
    {
        // Arrange
        var ingoing = new AltersGruppeIngoing
        {
            Name = "Seniors",
            StartingAge = 60,
            EndingAge = 100
        };

        // Act
        var result = ingoing.ToInternalFromIngoing();

        // Assert
        Assert.Equal(60, result.StartingAge);
        Assert.Equal(100, result.EndingAge);
    }
}
