using OF_DL.Models.Dtos.Common;
using OF_DL.Models.Dtos.Messages;
using OF_DL.Models.Dtos.Purchased;
using OF_DL.Models.Entities.Purchased;
using OF_DL.Models.Mappers;
using FromUserDto = OF_DL.Models.Dtos.Purchased.FromUserDto;
using ListItemDto = OF_DL.Models.Dtos.Purchased.ListItemDto;

namespace OF_DL.Tests.Models.Mappers;

public class PurchasedMapperTests
{
    [Fact]
    public void FromDto_ReturnsDefaults_WhenDtoNull()
    {
        Purchased result = PurchasedMapper.FromDto(null);

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

    [Fact]
    public void FromDto_MapsListItems()
    {
        DateTime createdAt = new(2024, 7, 8, 9, 10, 11, DateTimeKind.Utc);

        PurchasedDto dto = new()
        {
            HasMore = true,
            List =
            [
                new ListItemDto
                {
                    Id = 111,
                    Text = "purchased",
                    Price = "12.34",
                    IsOpened = true,
                    IsArchived = true,
                    CreatedAt = createdAt,
                    PostedAt = createdAt,
                    FromUser = new FromUserDto { Id = 0 },
                    Author = new AuthorDto { Id = 5 },
                    Media =
                    [
                        new MediumDto
                        {
                            Id = 222,
                            Type = "video",
                            CanView = true,
                            Files = new FilesDto { Full = new FullDto { Url = "https://example.com/full.mp4" } }
                        }
                    ]
                }
            ]
        };

        Purchased result = PurchasedMapper.FromDto(dto);

        Assert.True(result.HasMore);
        Assert.Single(result.List);

        ListItem item = result.List[0];
        Assert.Equal(111, item.Id);
        Assert.Equal("purchased", item.Text);
        Assert.Equal("12.34", item.Price);
        Assert.True(item.IsOpened);
        Assert.True(item.IsArchived);
        Assert.Equal(createdAt, item.CreatedAt);
        Assert.Equal(createdAt, item.PostedAt);
        Assert.NotNull(item.Author);
        Assert.Equal(5, item.Author.Id);
        Assert.Null(item.FromUser);
        Assert.NotNull(item.Media);
        Assert.Single(item.Media);
        Assert.Equal(222, item.Media[0].Id);
    }
}
