using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using Sony.Filtr.Contracts.Definitions; using Sony.Filtr.Contracts.Entities; using Sony.Filtr.Core.EditorialPlaylists; using Sony.Filtr.Utility; namespace Sony.Filtr.API.ViewModels.v2 { [DataContract] [Serializable] public class PlaylistViewModel { public PlaylistViewModel(Release release, int index, List tags, string baseUrl) { Id = "release-" + release.ID; Label = release.AlbumName; Artist = release.ArtistName; SpotifyUri = release.AlbumLink.Uri; Tags = tags; Index = index+1; //Start index at 1 ReleaseType = release.ReleaseType; if (baseUrl != null) { if (!string.IsNullOrWhiteSpace(release.ImageFilename)) SpotifyImageUrl = baseUrl + "/" + release.ImageFilename; } if (release.ReleaseType == ReleaseType.Album) { Categories = new List() { new TagViewModel() {ID = "category-album", Label = "album", Type = "Category"} }; } else if (release.ReleaseType == ReleaseType.Single) { if (release.TrackName != null) Label = release.TrackName; Categories = new List() { new TagViewModel() {ID = "category-single", Label = "single", Type = "Category"} }; } if (release.Energy.HasValue) Energy = release.Energy.Value; if (release.Hotness.HasValue) Hotness = release.Hotness.Value; //if (release.Danceability.HasValue) // Danceability = release.Danceability.Value; if (release.Tempo.HasValue) Tempo = release.Tempo.Value; } public PlaylistViewModel(EditorialPlaylistWithStats playlistStat, List tags, List categories, string baseUrl, EditorialPlaylistAttributes attributes) { var playlist = playlistStat.Playlist; Id = playlist.ID.ToString(); Slug = TextUtility.GenerateSlug(playlist.DisplayName ?? playlist.Name); SpotifyUri = playlist.SpotifyLink.Uri; Tags = tags; Label = playlist.Name; DisplayName = playlist.DisplayName ?? playlist.Name; Description = playlist.Description; SpotifyDescription = playlist.SpotifyDescription; Categories = categories; CountryCode = playlist.CountryCode; string headerImageUrl = null; if (!string.IsNullOrWhiteSpace(playlist.HeaderImageUrl)) headerImageUrl = baseUrl + "/" + playlist.HeaderImageUrl; string spotifyImageUrl = null; if (!string.IsNullOrWhiteSpace(playlist.SpotifyImageFileName)) spotifyImageUrl = baseUrl + "/" + playlist.SpotifyImageFileName; SpotifyImageUrl = spotifyImageUrl; Theme = new ThemeViewModel() { Active = playlist.ThemeActive, //BackgroundColor = playlist.BackgroundColor, //HeaderBackgroundColor = playlist.HeaderBackgroundColor, HeaderBackgroundImage = headerImageUrl, //TextColor = playlist.TextColor, AccentColor = playlist.AccentColor, }; Followers = playlistStat.LatestSubscribers; PriorityLevel = playlist.PriorityLevel; if (attributes != null) { if (attributes.TrackDuration.HasValue) TrackDuration = (int)attributes.TrackDuration; if (attributes.TrackCount.HasValue) TracksCount = (int)attributes.TrackCount.Value; if (attributes.TracksAddedThisWeek.HasValue) TracksAddedThisWeek = (int)attributes.TracksAddedThisWeek.Value; if (attributes.TracksAddedToday.HasValue) TracksAddedToday = (int)attributes.TracksAddedToday.Value; if (attributes.Changed.HasValue) TracksLastAdded = attributes.Changed.Value.ToString("O"); if (attributes.Energy.HasValue) Energy = attributes.Energy.Value; if (attributes.Hotness.HasValue) Hotness = attributes.Hotness.Value; if (attributes.Tempo.HasValue) Tempo = attributes.Tempo.Value; if (attributes.FollowerChange7.HasValue) FollowerChange7 = attributes.FollowerChange7.Value; if (attributes.FollowerChange15.HasValue) FollowerChange15 = attributes.FollowerChange15.Value; if (attributes.FollowerChange30.HasValue) FollowerChange30 = attributes.FollowerChange30.Value; } } [DataMember(Name = "id")] public string Id { get; set; } [DataMember(Name = "slug")] public string Slug { get; set; } [DataMember(Name = "spotifyUri")] public string SpotifyUri { get; set; } [DataMember(Name = "categories")] public List Categories { get; set; } [DataMember(Name = "tags")] public List Tags { get; set; } [DataMember(Name = "description")] public string Description { get; set; } [DataMember(Name = "spotifyDescription")] public string SpotifyDescription { get; set; } [DataMember(Name = "label")] public string Label { get; set; } [DataMember(Name = "countryCode")] public string CountryCode { get; set; } [DataMember(Name = "match", EmitDefaultValue = false)] public int Match { get; set; } [DataMember(Name = "theme", EmitDefaultValue = false)] public ThemeViewModel Theme { get; set; } [DataMember(Name = "followers", EmitDefaultValue = false)] public uint Followers { get; set; } [DataMember(Name = "releaseType", EmitDefaultValue = false)] public ReleaseType ReleaseType { get; set; } [DataMember(Name = "artist", EmitDefaultValue = false)] public string Artist { get; set; } [DataMember(Name = "index", EmitDefaultValue = false)] public int Index { get; set; } [DataMember(Name = "priorityLevel", EmitDefaultValue = false)] public int PriorityLevel { get; set; } [DataMember(Name = "spotifyImageUrl", EmitDefaultValue = false)] public string SpotifyImageUrl { get; set; } [DataMember(Name = "displayName", EmitDefaultValue = false)] public string DisplayName { get; set; } [DataMember(Name = "tracksAddedThisWeek", EmitDefaultValue = false)] public int TracksAddedThisWeek { get; set; } [DataMember(Name = "tracksAddedToday", EmitDefaultValue = false)] public int TracksAddedToday { get; set; } [DataMember(Name = "trackDuration", EmitDefaultValue = false)] public int TrackDuration { get; set; } [DataMember(Name = "tracksCount", EmitDefaultValue = false)] public int TracksCount { get; set; } [DataMember(Name = "tracksLastAdded", EmitDefaultValue = false)] public string TracksLastAdded { get; set; } [DataMember(Name = "energy", EmitDefaultValue = false)] public double Energy { get; set; } [DataMember(Name = "hotness", EmitDefaultValue = false)] public double Hotness { get; set; } [DataMember(Name = "tempo", EmitDefaultValue = false)] public double Tempo { get; set; } [DataMember(Name = "followerChange7", EmitDefaultValue = false)] public long FollowerChange7 { get; set; } [DataMember(Name = "followerChange15", EmitDefaultValue = false)] public long FollowerChange15 { get; set; } [DataMember(Name = "followerChange30", EmitDefaultValue = false)] public long FollowerChange30 { get; set; } } }