using Sony.Filtr.ApolloAPI.Models; using Sony.Filtr.SpotifyWebAPI.Model; using System; using System.Collections.Generic; using System.Linq; namespace Sony.Filtr.VendorToSpotify { public static class ApolloToSpotifyModelsExtensions { public static List ToSpotify(this IEnumerable apolloModel) { if (apolloModel == null) { return null; } return apolloModel.Select(a => a.ToSpotify()).ToList(); } public static SimplifiedPlaylist ToSpotify(this SpotifySimplifiedPlaylist apolloModel) { if (apolloModel == null) { return null; } return new SimplifiedPlaylist() { collaborative = apolloModel.collaborative, external_urls = apolloModel.external_urls.ToSpotify(), href = apolloModel.href, id = apolloModel.id, images = apolloModel.images.ToSpotify(), name = apolloModel.name, owner = apolloModel.owner.ToSpotify(), PlaylistTracks = apolloModel.PlaylistTracks.ToSpotify(), @public = apolloModel.@public, snapshot_id = apolloModel.snapshot_id, type = apolloModel.type, uri = apolloModel.uri }; } public static PlaylistResponse ToSpotify(this SpotifyPlaylist apolloModel) { if (apolloModel == null) { return null; } return new PlaylistResponse { collaborative = apolloModel.collaborative, description = apolloModel.description, external_urls = apolloModel.external_urls.ToSpotify(), followers = apolloModel.followers.ToSpotify(), href = apolloModel.href, id = apolloModel.id, images = apolloModel.images.ToSpotify(), name = apolloModel.name, owner = apolloModel.owner.ToSpotify(), @public = apolloModel.@public, snapshot_id = apolloModel.snapshot_id, type = apolloModel.type, uri = apolloModel.uri, Tracks = apolloModel.Tracks.ToSpotify(), HasSnapshotIdChanged = apolloModel.HasSnapshotIdChanged }; } public static ExternalUrls ToSpotify(this SpotifyExternalUrls apolloModel) { if (apolloModel == null) { return new ExternalUrls(); } return new ExternalUrls { spotify = apolloModel.spotify, }; } public static Followers ToSpotify(this SpotifyFollowers apolloModel) { if (apolloModel == null) { return new Followers(); } return new Followers { href = apolloModel.href, total = apolloModel.total }; } public static Owner ToSpotify(this SpotifyOwner apolloModel) { if (apolloModel == null) { return new Owner(); } return new Owner { href = apolloModel.href, id = apolloModel.id, type = apolloModel.type, uri = apolloModel.uri, external_urls = apolloModel.external_urls.ToSpotify() }; } public static PlaylistTracks ToSpotify(this SpotifyPlaylistTracks apolloModel) { if (apolloModel == null) { return new PlaylistTracks(); } return new PlaylistTracks { href = apolloModel.href, total = apolloModel.total, limit = apolloModel.limit, next = apolloModel.next, offset = apolloModel.offset, previous = apolloModel.previous, items = apolloModel.items.ToSpotify() }; } public static List ToSpotify(this IEnumerable apolloModel) { if (apolloModel == null) { return null; } return apolloModel.Select(i => i.ToSpotify()).ToList(); } public static PlaylistTrackItem ToSpotify(this SpotifyPlaylistTrackItem apolloModel) { if (apolloModel == null) { return new PlaylistTrackItem(); } return new PlaylistTrackItem { added_at = apolloModel.added_at, added_by = apolloModel.added_by.ToSpotify(), is_local = apolloModel.is_local, track = apolloModel.track.ToSpotify() }; } public static AddedBy ToSpotify(this SpotifyAddedBy apolloModel) { if (apolloModel == null) { return new AddedBy(); } return new AddedBy { external_urls = apolloModel.external_urls.ToSpotify(), href = apolloModel.href, id = apolloModel.id, type = apolloModel.type, uri = apolloModel.uri }; } public static Track ToSpotify(this SpotifyTrack apolloModel) { if (apolloModel == null) { return new Track(); } return new Track { album = apolloModel.album.ToSpotify(), uri = apolloModel.uri, type = apolloModel.type, id = apolloModel.id, href = apolloModel.href, external_ids = apolloModel.external_ids.ToSpotify(), artists = apolloModel.artists.ToSpotify(), available_markets = apolloModel.available_markets, disc_number = apolloModel.disc_number, duration_ms = apolloModel.duration_ms, @explicit = apolloModel.@explicit, external_urls = apolloModel.external_urls.ToSpotify(), is_playable = apolloModel.is_playable, linked_from = apolloModel.linked_from.ToSpotify(), name = apolloModel.name, popularity = apolloModel.popularity, preview_url = apolloModel.preview_url, track_number = apolloModel.track_number }; } public static List ToSpotify(this List apolloModel) { if (apolloModel == null) { return null; } return apolloModel.Select(a => a.ToSpotify()).ToList(); } public static Album ToSpotify(this SpotifyAlbum apolloModel) { if (apolloModel == null) { return new Album(); } return new Album { album_type = apolloModel.album_type, artists = apolloModel.artists.ToSpotify(), available_markets = apolloModel.available_markets, external_urls = apolloModel.external_urls.ToSpotify(), href = apolloModel.href, id = apolloModel.id, images = apolloModel.images.ToSpotify(), name = apolloModel.name, type = apolloModel.type, uri = apolloModel.uri }; } public static AlbumTracks ToSpotify(this SpotifyAlbumTracks apolloModel) { if (apolloModel == null) { return null; } return new AlbumTracks() { href = apolloModel.href, limit = apolloModel.limit, next = apolloModel.next, offset = apolloModel.offset, previous = apolloModel.previous, total = apolloModel.total, items = apolloModel.items.ToSpotify() }; } public static List ToSpotify(this IEnumerable apolloModel) { if (apolloModel == null) { return null; } return apolloModel.Select(a => a.ToSpotify()).ToList(); } public static List ToSpotify(this IEnumerable apolloModel) { if (apolloModel == null) { return null; } return apolloModel.Select(a => a.ToSpotify()).ToList(); } public static Copyright ToSpotify(this SpotifyCopyright apolloModel) { if (apolloModel == null) { return null; } return new Copyright() { text = apolloModel.text, type = apolloModel.type }; } public static List ToFullItem(this IEnumerable apolloModel) { if (apolloModel == null) { return null; } return apolloModel.Select(a => a.ToFullItem()).ToList(); } public static FullAlbumItem ToFullItem(this SpotifyAlbum apolloModel) { if (apolloModel == null) { return null; } return new FullAlbumItem { album_type = ToAlbumType(apolloModel.album_type), artists = apolloModel.artists.ToSpotify(), available_markets = apolloModel.available_markets, external_urls = apolloModel.external_urls.ToSpotify(), href = apolloModel.href, id = apolloModel.id, images = apolloModel.images.ToSpotify(), name = apolloModel.name, type = apolloModel.type, uri = apolloModel.uri, copyrights = apolloModel.copyrights.ToSpotify(), tracks = apolloModel.tracks.ToSpotify(), external_ids = apolloModel.external_ids.ToSpotify(), label = apolloModel.label, popularity = apolloModel.popularity, release_date = apolloModel.release_date, release_date_precision = apolloModel.release_date_precision }; } private static AlbumType ToAlbumType(string str) { if (Enum.TryParse(str, out AlbumType type)) { return type; } return AlbumType.album; } public static ExternalIds ToSpotify(this SpotifyExternalIds apolloModel) { if (apolloModel == null) { return new ExternalIds(); } return new ExternalIds { isrc = apolloModel.isrc, upc = apolloModel.upc }; } public static Artist ToSpotify(this SpotifyArtist apolloModel) { if (apolloModel == null) { return new Artist(); } return new Artist { external_urls = apolloModel.external_urls.ToSpotify(), uri = apolloModel.uri, type = apolloModel.type, name = apolloModel.name, followers = apolloModel.followers.ToSpotify(), href = apolloModel.href, id = apolloModel.id, images = apolloModel.images.ToSpotify(), popularity = apolloModel.popularity }; } public static LinkedFrom ToSpotify(this SpotifyLinkedFrom apolloModel) { if (apolloModel == null) { return new LinkedFrom(); } return new LinkedFrom { external_urls = apolloModel.external_urls.ToSpotify(), href = apolloModel.href, id = apolloModel.id, type = apolloModel.type, uri = apolloModel.uri }; } public static List ToSpotify(this List apolloModel) { if (apolloModel == null) { return null; } return apolloModel.Select(i => i.ToSpotify()).ToList(); } public static Image ToSpotify(this SpotifyImage apolloModel) { if (apolloModel == null) { return new Image(); } return new Image { height = apolloModel.height, url = apolloModel.url, width = apolloModel.width }; } } }