#pragma once #include #include #include #include #include #include #include namespace Spotify::Request { // ============================================================================ // Base Request Parameter Class // ============================================================================ class RequestParams { public: virtual ~RequestParams() = default; virtual auto ToQueryParams() const -> std::map = 0; }; // ============================================================================ // Search Type Enum // ============================================================================ enum class SearchType { Album, Artist, Playlist, Track, Show, Episode, Audiobook }; inline auto SearchTypeToString(SearchType type) -> std::string { switch (type) { case SearchType::Album: return "album"; case SearchType::Artist: return "artist"; case SearchType::Playlist: return "playlist"; case SearchType::Track: return "track"; case SearchType::Show: return "show"; case SearchType::Episode: return "episode"; case SearchType::Audiobook: return "audiobook"; } return ""; } // ============================================================================ // Time Range Enum // ============================================================================ enum class TimeRange { LongTerm, MediumTerm, ShortTerm }; inline auto TimeRangeToString(TimeRange range) -> std::string { switch (range) { case TimeRange::LongTerm: return "long_term"; case TimeRange::MediumTerm: return "medium_term"; case TimeRange::ShortTerm: return "short_term"; } return "medium_term"; } // ============================================================================ // Pagination Parameters // ============================================================================ struct PaginationParams : public RequestParams { public: std::optional limit = 20; std::optional offset = 0; std::optional market; auto ToQueryParams() const -> std::map override { std::map params; if (limit) params["limit"] = std::to_string(*limit); if (offset) params["offset"] = std::to_string(*offset); if (market) params["market"] = *market; return params; } }; // ============================================================================ // Search Parameters // ============================================================================ struct SearchParams : public RequestParams { public: //You can narrow down your search using field filters. The available filters are album, artist, track, year, upc, tag:hipster, tag:new, isrc, and genre. Each field filter only applies to certain result types. //The artist and year filters can be used while searching albums, artists and tracks. You can filter on a single year or a range (e.g. 1955-1960). //The album filter can be used while searching albums and tracks. //The genre filter can be used while searching artists and tracks. //The isrc and track filters can be used while searching tracks. //The upc, tag:new and tag:hipster filters can only be used while searching albums. The tag:new filter will return albums released in the past two weeks and tag:hipster can be used to return only albums with the lowest 10% popularity. //Example: q=remaster%2520track%3ADoxy%2520artist%3AMiles%2520Davis std::string query; std::vector types; std::optional market; std::optional limit = 20; std::optional offset = 0; std::optional include_external; auto ToQueryParams() const -> std::map override { std::map params; params["q"] = query; std::vector type_strings; for (const auto& type : types) { type_strings.push_back(SearchTypeToString(type)); } params["type"] = std::views::join_with(type_strings, ',') | std::ranges::to(); if (market) params["market"] = *market; if (limit) params["limit"] = std::to_string(*limit); if (offset) params["offset"] = std::to_string(*offset); if (include_external) params["include_external"] = *include_external ? "audio" : ""; return params; } }; // ============================================================================ // Track Search Filters // ============================================================================ struct TrackSearchFilters : public RequestParams { public: std::optional track; std::optional artist; std::optional album; std::optional year; std::optional genre; std::optional isrc; std::optional upc; std::optional is_new; std::optional hipster; auto ToQueryString() const -> std::string { std::vector parts; if (track) parts.push_back(std::format("track:{}", *track)); if (artist) parts.push_back(std::format("artist:{}", *artist)); if (album) parts.push_back(std::format("album:{}", *album)); if (year) parts.push_back(std::format("year:{}", *year)); if (genre) parts.push_back(std::format("genre:{}", *genre)); if (isrc) parts.push_back(std::format("isrc:{}", *isrc)); if (upc) parts.push_back(std::format("upc:{}", *upc)); if (is_new && *is_new) parts.push_back("tag:new"); if (hipster && *hipster) parts.push_back("tag:hipster"); return std::views::join_with(parts, ' ') | std::ranges::to(); } auto ToQueryParams() const -> std::map override { return {}; } }; // ============================================================================ // Album Search Filters // ============================================================================ struct AlbumSearchFilters : public RequestParams { public: std::optional album; std::optional artist; std::optional year; std::optional genre; std::optional upc; auto ToQueryString() const -> std::string { std::vector parts; if (album) parts.push_back(std::format("album:{}", *album)); if (artist) parts.push_back(std::format("artist:{}", *artist)); if (year) parts.push_back(std::format("year:{}", *year)); if (genre) parts.push_back(std::format("genre:{}", *genre)); if (upc) parts.push_back(std::format("upc:{}", *upc)); return std::views::join_with(parts, ' ') | std::ranges::to(); } auto ToQueryParams() const -> std::map override { return {}; } }; // ============================================================================ // Artist Search Filters // ============================================================================ struct ArtistSearchFilters : public RequestParams { public: std::optional artist; std::optional genre; auto ToQueryString() const -> std::string { std::vector parts; if (artist) parts.push_back(std::format("artist:{}", *artist)); if (genre) parts.push_back(std::format("genre:{}", *genre)); return std::views::join_with(parts, ' ') | std::ranges::to(); } auto ToQueryParams() const -> std::map override { return {}; } }; // ============================================================================ // Album Tracks Parameters // ============================================================================ struct AlbumTracksParams : public RequestParams { public: std::optional limit = 20; std::optional offset = 0; std::optional market; auto ToQueryParams() const -> std::map override { std::map params; if (limit) params["limit"] = std::to_string(*limit); if (offset) params["offset"] = std::to_string(*offset); if (market) params["market"] = *market; return params; } }; // ============================================================================ // Artist Albums Parameters // ============================================================================ struct ArtistAlbumsParams : public RequestParams { public: std::optional> include_groups; std::optional market; std::optional limit = 20; std::optional offset = 0; auto ToQueryParams() const -> std::map override { std::map params; if (include_groups && !include_groups->empty()) { params["include_groups"] = std::views::join_with(*include_groups, ',') | std::ranges::to(); } if (market) params["market"] = *market; if (limit) params["limit"] = std::to_string(*limit); if (offset) params["offset"] = std::to_string(*offset); return params; } }; // ============================================================================ // Top Items Parameters // ============================================================================ struct TopItemsParams : public RequestParams { public: std::optional time_range = TimeRange::MediumTerm; std::optional limit = 20; std::optional offset = 0; auto ToQueryParams() const -> std::map override { std::map params; if (time_range) params["time_range"] = TimeRangeToString(*time_range); if (limit) params["limit"] = std::to_string(*limit); if (offset) params["offset"] = std::to_string(*offset); return params; } }; // ============================================================================ // Recommendation Parameters // ============================================================================ struct RecommendationParams : public RequestParams { public: std::optional> seed_artists; std::optional> seed_genres; std::optional> seed_tracks; std::optional limit = 20; std::optional market; // Tunable attributes std::optional min_acousticness; std::optional max_acousticness; std::optional target_acousticness; std::optional min_danceability; std::optional max_danceability; std::optional target_danceability; std::optional min_duration_ms; std::optional max_duration_ms; std::optional target_duration_ms; std::optional min_energy; std::optional max_energy; std::optional target_energy; std::optional min_instrumentalness; std::optional max_instrumentalness; std::optional target_instrumentalness; std::optional min_key; std::optional max_key; std::optional target_key; std::optional min_liveness; std::optional max_liveness; std::optional target_liveness; std::optional min_loudness; std::optional max_loudness; std::optional target_loudness; std::optional min_mode; std::optional max_mode; std::optional target_mode; std::optional min_popularity; std::optional max_popularity; std::optional target_popularity; std::optional min_speechiness; std::optional max_speechiness; std::optional target_speechiness; std::optional min_tempo; std::optional max_tempo; std::optional target_tempo; std::optional min_time_signature; std::optional max_time_signature; std::optional target_time_signature; std::optional min_valence; std::optional max_valence; std::optional target_valence; auto ToQueryParams() const -> std::map override { std::map params; if (seed_artists && !seed_artists->empty()) { params["seed_artists"] = std::views::join_with(*seed_artists, ',') | std::ranges::to(); } if (seed_genres && !seed_genres->empty()) { params["seed_genres"] = std::views::join_with(*seed_genres, ',') | std::ranges::to(); } if (seed_tracks && !seed_tracks->empty()) { params["seed_tracks"] = std::views::join_with(*seed_tracks, ',') | std::ranges::to(); } if (limit) params["limit"] = std::to_string(*limit); if (market) params["market"] = *market; // Add all tunable attributes if (min_acousticness) params["min_acousticness"] = std::to_string(*min_acousticness); if (max_acousticness) params["max_acousticness"] = std::to_string(*max_acousticness); if (target_acousticness) params["target_acousticness"] = std::to_string(*target_acousticness); if (min_danceability) params["min_danceability"] = std::to_string(*min_danceability); if (max_danceability) params["max_danceability"] = std::to_string(*max_danceability); if (target_danceability) params["target_danceability"] = std::to_string(*target_danceability); if (min_energy) params["min_energy"] = std::to_string(*min_energy); if (max_energy) params["max_energy"] = std::to_string(*max_energy); if (target_energy) params["target_energy"] = std::to_string(*target_energy); if (min_popularity) params["min_popularity"] = std::to_string(*min_popularity); if (max_popularity) params["max_popularity"] = std::to_string(*max_popularity); if (target_popularity) params["target_popularity"] = std::to_string(*target_popularity); // Add remaining attributes as needed... return params; } }; // ============================================================================ // Create Playlist Parameters // ============================================================================ struct CreatePlaylistParams { std::string name; std::optional public_playlist = true; std::optional collaborative = false; std::optional description; }; // ============================================================================ // Update Playlist Parameters // ============================================================================ struct UpdatePlaylistParams { std::optional name; std::optional public_playlist; std::optional collaborative; std::optional description; }; // ============================================================================ // Playlist Track Operations // ============================================================================ struct AddTracksToPlaylistParams { std::vector uris; std::optional position; }; struct RemoveTracksFromPlaylistParams { std::vector uris; std::optional snapshot_id; }; struct ReorderPlaylistParams { int range_start; int insert_before; std::optional range_length = 1; std::optional snapshot_id; }; struct ReplacePlaylistTracksParams { std::vector uris; }; // ============================================================================ // Playback Control Parameters // ============================================================================ struct PlayParams { std::optional context_uri; std::optional> uris; std::optional> offset; std::optional position_ms; }; struct TransferPlaybackParams { std::vector device_ids; std::optional play; }; struct QueueParams { std::string uri; std::optional device_id; }; struct RequestBody { std::vector ids; }; // ============================================================================ // Follow Parameters // ============================================================================ struct ErrorResponse { struct Error { int status; std::string message; } error; }; enum class FollowType { Artist, User }; inline auto FollowTypeToString(FollowType type) -> std::string { return type == FollowType::Artist ? "artist" : "user"; } struct FollowParams { FollowType type; std::vector ids; }; struct UnfollowParams { FollowType type; std::vector ids; }; struct CheckFollowingParams { FollowType type; std::vector ids; }; struct FollowPlaylistParams { std::optional public_playlist = true; }; } // namespace Spotify::Request