using System.Collections.Generic; using System.Linq; using Sony.Filtr.Functional; namespace Sony.Filtr.ApolloAPI.Models { public class FavoritePlaylistsResponse { public string[] Playlists { get; set; } public PlaylistFavorites Normalize() { /* "spotify_None_3ZTL8MBRGOWvGwU75d6jPi", "apple_us_pl.6db5f7b47286460e9928d09d9ac0be69", */ return this.Playlists .Select(p => p.Split('_')) .Aggregate( (new List(), new List<(string, string)>()), (acc, vendor_market_id) => { switch (vendor_market_id[0].ToLower()) { case "spotify": { acc.Item1.Add(vendor_market_id[2]); break; } case "apple": { acc.Item2.Add((vendor_market_id[1], vendor_market_id[2])); break; } default: break; } return acc; }) .ToResult() .Bind(tuple => new PlaylistFavorites(tuple.Item1, tuple.Item2)) .Flatten(); } } public class PlaylistFavorites { public readonly string[] SpotifyPlaylistIds; public readonly (string Market, string Id)[] ApplePlaylists; public PlaylistFavorites(IEnumerable spoitfyIds, IEnumerable<(string, string)> appleIds) { this.SpotifyPlaylistIds = spoitfyIds.ToArray(); this.ApplePlaylists = appleIds.ToArray(); } } }