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

namespace OF_DL.Tests.Models.Mappers;

public class ArchivedMapperTests
{
    [Fact]
    public void FromDto_ReturnsDefaults_WhenDtoNull()
    {
        Archived result = ArchivedMapper.FromDto(null);

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

    [Fact]
    public void FromDto_MapsListItems()
    {
        DateTime postedAt = new(2024, 1, 2, 3, 4, 5, DateTimeKind.Utc);

        ArchivedDto dto = new()
        {
            HasMore = true,
            TailMarker = "tail",
            List =
            [
                new ListItemDto
                {
                    Id = 123,
                    PostedAt = postedAt,
                    Author = new AuthorDto { Id = 7 },
                    Text = "hello",
                    Price = "9.99",
                    IsOpened = true,
                    IsArchived = true,
                    Preview = ["preview"],
                    Media =
                    [
                        new MediumDto
                        {
                            Id = 456,
                            Type = "photo",
                            CanView = true,
                            Files = new FilesDto { Full = new FullDto { Url = "https://example.com/full.jpg" } }
                        }
                    ]
                }
            ]
        };

        Archived result = ArchivedMapper.FromDto(dto);

        Assert.True(result.HasMore);
        Assert.Equal("tail", result.TailMarker);
        Assert.Single(result.List);

        ListItem item = result.List[0];
        Assert.Equal(123, item.Id);
        Assert.Equal(postedAt, item.PostedAt);
        Assert.NotNull(item.Author);
        Assert.Equal(7, item.Author.Id);
        Assert.Equal("hello", item.Text);
        Assert.Equal("9.99", item.Price);
        Assert.True(item.IsOpened);
        Assert.True(item.IsArchived);
        Assert.NotNull(item.Media);
        Assert.Single(item.Media);

        Medium media = item.Media[0];
        Assert.Equal(456, media.Id);
        Assert.Equal("photo", media.Type);
        Assert.NotNull(media.Files);
        Assert.NotNull(media.Files.Full);
        Assert.Equal("https://example.com/full.jpg", media.Files.Full.Url);
    }
}
