qobuz_api_rust/models/
search.rs

1use serde::{Deserialize, Serialize};
2
3use crate::models::{
4    Album, Article, Artist, MostPopular as MostPopularModel, Playlist, Story, Track, User,
5};
6
7/// Generic search result model for items
8///
9/// This struct represents a paginated search result containing a list of items
10/// of type T, along with metadata about the total count, pagination limits, and
11/// whether more results are available.
12///
13/// # Type Parameters
14///
15/// * `T` - The type of items contained in the search result
16///
17/// # Examples
18///
19/// ```
20/// use qobuz_api_rust::models::ItemSearchResult;
21///
22/// let result: ItemSearchResult<String> = ItemSearchResult {
23///     items: Some(vec!["item1".to_string(), "item2".to_string()]),
24///     total: Some(100),
25///     limit: Some(10),
26///     offset: Some(0),
27///     has_more: Some(true),
28/// };
29/// ```
30#[derive(Serialize, Deserialize, Debug, Clone)]
31pub struct ItemSearchResult<T> {
32    /// List of items in the search result
33    #[serde(rename = "items")]
34    pub items: Option<Vec<T>>,
35
36    /// Total number of items matching the search criteria
37    #[serde(rename = "total")]
38    pub total: Option<i32>,
39
40    /// Maximum number of items returned per page
41    #[serde(rename = "limit")]
42    pub limit: Option<i32>,
43
44    /// Offset indicating how many items were skipped
45    #[serde(rename = "offset")]
46    pub offset: Option<i32>,
47
48    /// Whether there are more items available beyond the current page
49    #[serde(rename = "has_more")]
50    pub has_more: Option<bool>,
51}
52
53// Implement Default trait for all structs to make testing easier
54impl<T> Default for ItemSearchResult<T> {
55    fn default() -> Self {
56        ItemSearchResult {
57            items: None,
58            total: None,
59            limit: None,
60            offset: None,
61            has_more: None,
62        }
63    }
64}
65
66/// Search result model containing results for various content types
67///
68/// This struct represents the results of a search operation across different
69/// content types including albums, articles, artists, playlists, and tracks.
70///
71/// # Examples
72///
73/// ```
74/// use qobuz_api_rust::models::{SearchResult, ItemSearchResult, Album, Artist};
75///
76/// let search_result = SearchResult {
77///     albums: Some(ItemSearchResult::<Album>::default()),
78///     artists: Some(ItemSearchResult::<Artist>::default()),
79///     query: Some("search query".to_string()),
80///     ..Default::default()
81/// };
82/// ```
83#[derive(Serialize, Deserialize, Debug, Clone, Default)]
84pub struct SearchResult {
85    /// Search results for albums
86    #[serde(rename = "albums")]
87    pub albums: Option<ItemSearchResult<Album>>,
88
89    /// Search results for articles
90    #[serde(rename = "articles")]
91    pub articles: Option<ItemSearchResult<Article>>,
92
93    /// Search results for artists
94    #[serde(rename = "artists")]
95    pub artists: Option<ItemSearchResult<Artist>>,
96
97    /// Search results for focus items
98    #[serde(rename = "focus")]
99    pub focus: Option<ItemSearchResult<Story>>,
100
101    /// Search results for most popular items
102    #[serde(rename = "most_popular")]
103    pub most_popular: Option<ItemSearchResult<MostPopularModel>>,
104
105    /// Search results for playlists
106    #[serde(rename = "playlists")]
107    pub playlists: Option<ItemSearchResult<Playlist>>,
108
109    /// The search query that was used
110    #[serde(rename = "query")]
111    pub query: Option<String>,
112
113    /// Search results for stories
114    #[serde(rename = "stories")]
115    pub stories: Option<ItemSearchResult<Story>>,
116
117    /// Search results for tracks
118    #[serde(rename = "tracks")]
119    pub tracks: Option<ItemSearchResult<Track>>,
120}
121
122/// Most popular model containing information about popular content
123///
124/// This struct represents information about the most popular content of a specific type.
125///
126/// # Examples
127///
128/// ```
129/// use qobuz_api_rust::models::{MostPopular, MostPopularContent};
130///
131/// let most_popular = MostPopular {
132///     content: MostPopularContent::default(),
133///     type_field: Some("album".to_string()),
134/// };
135/// ```
136#[derive(Serialize, Deserialize, Debug, Clone, Default)]
137pub struct MostPopular {
138    /// Content information for the most popular item
139    #[serde(rename = "content")]
140    pub content: MostPopularContent,
141
142    /// Type of the most popular content
143    #[serde(rename = "type")]
144    pub type_field: Option<String>,
145}
146
147/// Most popular content model containing type information
148///
149/// This struct represents the content type for most popular items.
150///
151/// # Examples
152///
153/// ```
154/// use qobuz_api_rust::models::MostPopularContent;
155///
156/// let content = MostPopularContent {
157///     type_field: Some("track".to_string()),
158/// };
159/// ```
160#[derive(Serialize, Deserialize, Debug, Clone, Default)]
161pub struct MostPopularContent {
162    /// Type of the content
163    #[serde(rename = "type")]
164    pub type_field: Option<String>,
165}
166
167/// User favorites model containing a user's favorite content
168///
169/// This struct represents a user's favorite content including albums, artists,
170/// tracks, and articles, along with the user information.
171///
172/// # Examples
173///
174/// ```
175/// use qobuz_api_rust::models::{UserFavorites, ItemSearchResult, Album, Artist, Track, Article};
176///
177/// let user_favorites = UserFavorites {
178///     user: None,
179///     albums: Some(ItemSearchResult::<Album>::default()),
180///     artists: Some(ItemSearchResult::<Artist>::default()),
181///     tracks: Some(ItemSearchResult::<Track>::default()),
182///     articles: Some(ItemSearchResult::<Article>::default()),
183/// };
184/// ```
185#[derive(Serialize, Deserialize, Debug, Clone, Default)]
186pub struct UserFavorites {
187    /// User information for the favorites
188    #[serde(rename = "user")]
189    pub user: Option<User>,
190
191    /// Search results for favorite albums
192    #[serde(rename = "albums")]
193    pub albums: Option<ItemSearchResult<Album>>,
194
195    /// Search results for favorite artists
196    #[serde(rename = "artists")]
197    pub artists: Option<ItemSearchResult<Artist>>,
198
199    /// Search results for favorite tracks
200    #[serde(rename = "tracks")]
201    pub tracks: Option<ItemSearchResult<Track>>,
202
203    /// Search results for favorite articles
204    #[serde(rename = "articles")]
205    pub articles: Option<ItemSearchResult<Article>>,
206}
207
208/// User favorites IDs model containing IDs of a user's favorite content
209///
210/// This struct represents the IDs of a user's favorite content including albums,
211/// articles, artists, and tracks.
212///
213/// # Examples
214///
215/// ```
216/// use qobuz_api_rust::models::UserFavoritesIds;
217///
218/// let favorites_ids = UserFavoritesIds {
219///     albums: Some(vec!["album1".to_string(), "album2".to_string()]),
220///     artists: Some(vec![123, 456]),
221///     tracks: Some(vec![789, 101112]),
222///     ..Default::default()
223/// };
224/// ```
225#[derive(Serialize, Deserialize, Debug, Clone, Default)]
226pub struct UserFavoritesIds {
227    /// List of favorite album IDs
228    #[serde(rename = "albums")]
229    pub albums: Option<Vec<String>>,
230
231    /// List of favorite article IDs
232    #[serde(rename = "articles")]
233    pub articles: Option<Vec<i64>>,
234
235    /// List of favorite artist IDs
236    #[serde(rename = "artists")]
237    pub artists: Option<Vec<i32>>,
238
239    /// List of favorite track IDs
240    #[serde(rename = "tracks")]
241    pub tracks: Option<Vec<i32>>,
242}
243
244/// Model containing albums by the same artist
245///
246/// This struct represents a collection of albums by the same artist along with
247/// information about the artist.
248///
249/// # Examples
250///
251/// ```
252/// use qobuz_api_rust::models::{AlbumsSameArtist, ItemSearchResult, Album};
253///
254/// let albums_same_artist = AlbumsSameArtist {
255///     albums: Some(ItemSearchResult::<Box<Album>>::default()),
256///     artist: None,
257/// };
258/// ```
259#[derive(Serialize, Deserialize, Debug, Clone, Default)]
260pub struct AlbumsSameArtist {
261    /// Search results for albums by the same artist
262    #[serde(rename = "albums")]
263    pub albums: Option<ItemSearchResult<Box<Album>>>,
264
265    /// The artist whose albums are included
266    #[serde(rename = "artist")]
267    pub artist: Option<Box<Artist>>,
268}