using System; using System.Collections.Generic; using System.Linq; namespace Sony.Filtr.ApolloAPI.Models.Apple { public class ApplePlaylistListChartSongsData { public readonly IReadOnlyList ChartSongs; public readonly DateTime PlaylistLastModifiedDate; public readonly string Storefront; public ApplePlaylistListChartSongsData(ApplePlaylistData playlist, string storefront) { this.ChartSongs = playlist?.relationships?.tracks?.data? .Where(p => p.attributes != null) .Select(t => new AppleChartSongData { attributes = GetAttributes(t.attributes), href = t.href, id = t.id, type = t.type }) .ToList() .AsReadOnly(); this.PlaylistLastModifiedDate = DateTime.Parse(playlist.attributes.lastModifiedDate); this.Storefront = storefront; } public bool HasData { get { return this.ChartSongs != null; } } private static AppleChartSongAttributes GetAttributes(AppleTrackAttributes trackAttributes) { return new AppleChartSongAttributes { artistName = trackAttributes.artistName, artwork = trackAttributes.artwork != null ? new AppleArtwork { bgColor = trackAttributes.artwork.bgColor, url = trackAttributes.artwork.url, height = trackAttributes.artwork.height, textColor1 = trackAttributes.artwork.textColor1, textColor2 = trackAttributes.artwork.textColor2, textColor3 = trackAttributes.artwork.textColor3, textColor4 = trackAttributes.artwork.textColor4, width = trackAttributes.artwork.width } : null, discNumber = trackAttributes.discNumber, durationInMillis = trackAttributes.durationInMillis, genreNames = trackAttributes.genreNames, name = trackAttributes.name, releaseDate = trackAttributes.releaseDate, trackNumber = trackAttributes.trackNumber, url = trackAttributes.url, isrc = trackAttributes.isrc }; } } }