using OF_DL.Models.Dtos.Subscriptions;
using OF_DL.Models.Entities.Subscriptions;

namespace OF_DL.Models.Mappers;

public static class SubscriptionsMapper
{
    public static Subscriptions FromDto(SubscriptionsDto? dto)
    {
        Subscriptions mapped = new() { HasMore = dto?.HasMore ?? false };

        if (dto?.List == null)
        {
            return mapped;
        }

        foreach (ListItemDto entry in dto.List)
        {
            mapped.List.Add(MapList(entry));
        }

        return mapped;
    }

    private static ListItem MapList(ListItemDto dto) =>
        new() { Id = dto.Id, Username = dto.Username ?? "", IsRestricted = dto.IsRestricted };
}
