using OF_DL.Models.Dtos.Common;
using OF_DL.Models.Dtos.Highlights;
using OF_DL.Models.Entities.Highlights;
using OF_DL.Models.Mappers;

namespace OF_DL.Tests.Models.Mappers;

public class HighlightsMapperTests
{
    [Fact]
    public void FromDto_ReturnsDefaults_WhenDtoNull()
    {
        Highlights result = HighlightsMapper.FromDto((HighlightsDto?)null);

        Assert.False(result.HasMore);
        Assert.Empty(result.List);
    }

    [Fact]
    public void FromDto_MapsListItems()
    {
        HighlightsDto dto = new() { HasMore = true, List = [new ListItemDto { Id = 99 }] };

        Highlights result = HighlightsMapper.FromDto(dto);

        Assert.True(result.HasMore);
        Assert.Single(result.List);
        Assert.Equal(99, result.List[0].Id);
    }

    [Fact]
    public void FromDto_MapsHighlightMediaStories()
    {
        DateTime createdAt = new(2024, 2, 3, 4, 5, 6, DateTimeKind.Utc);

        HighlightMediaDto dto = new()
        {
            Stories =
            [
                new StoryDto
                {
                    Id = 5,
                    CreatedAt = createdAt,
                    Media =
                    [
                        new MediumDto
                        {
                            Id = 8,
                            Type = "video",
                            CanView = true,
                            CreatedAt = createdAt,
                            Files = new FilesDto { Full = new FullDto { Url = "https://example.com/full.mp4" } }
                        }
                    ]
                }
            ]
        };

        HighlightMedia result = HighlightsMapper.FromDto(dto);

        Assert.Single(result.Stories);

        Story story = result.Stories[0];
        Assert.Equal(5, story.Id);
        Assert.Equal(createdAt, story.CreatedAt);
        Assert.NotNull(story.Media);
        Assert.Single(story.Media);

        Medium media = story.Media[0];
        Assert.Equal(8, media.Id);
        Assert.NotNull(media.Files);
        Assert.NotNull(media.Files.Full);
        Assert.Equal("https://example.com/full.mp4", media.Files.Full.Url);
    }
}
