using OF_DL.Models.Dtos.Common;
using OF_DL.Models.Dtos.Stories;
using OF_DL.Models.Entities.Common;
using OF_DL.Models.Entities.Stories;

namespace OF_DL.Models.Mappers;

public static class StoriesMapper
{
    public static List<Stories> FromDto(List<StoryDto>? dto) =>
        dto == null ? [] : dto.Select(MapStory).ToList();

    private static Stories MapStory(StoryDto dto) =>
        new() { Id = dto.Id, CreatedAt = dto.CreatedAt, Media = MapMedia(dto.Media) };

    private static List<Medium> MapMedia(List<MediumDto>? media) =>
        media == null ? [] : media.Select(MapMedium).ToList();

    private static Medium MapMedium(MediumDto dto) =>
        new()
        {
            Id = dto.Id,
            Type = dto.Type,
            CanView = dto.CanView,
            CreatedAt = dto.CreatedAt,
            Files = MapFiles(dto.Files)
        };

    private static Files MapFiles(FilesDto? dto) =>
        new() { Full = CommonMapper.MapFull(dto?.Full) };
}
