Skip to main content

rspotify_model/
recommend.rs

1//! All objects related to recommendation
2
3use serde::{Deserialize, Serialize};
4use strum::IntoStaticStr;
5
6use crate::{RecommendationsSeedType, SimplifiedTrack};
7
8/// Recommendations object
9#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
10pub struct Recommendations {
11    pub seeds: Vec<RecommendationsSeed>,
12    pub tracks: Vec<SimplifiedTrack>,
13}
14
15/// Recommendations seed object
16#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
17pub struct RecommendationsSeed {
18    #[serde(rename = "afterFilteringSize")]
19    pub after_filtering_size: u32,
20    #[serde(rename = "afterRelinkingSize")]
21    pub after_relinking_size: u32,
22    pub href: Option<String>,
23    pub id: String,
24    #[serde(rename = "initialPoolSize")]
25    pub initial_pool_size: u32,
26    #[serde(rename = "type")]
27    pub _type: RecommendationsSeedType,
28}
29
30/// The attributes for recommendations
31#[derive(Clone, Copy, Debug, Serialize, PartialEq, IntoStaticStr)]
32#[serde(rename_all = "snake_case")]
33#[strum(serialize_all = "snake_case")]
34pub enum RecommendationsAttribute {
35    MinAcousticness(f32),
36    MaxAcousticness(f32),
37    TargetAcousticness(f32),
38    MinDanceability(f32),
39    MaxDanceability(f32),
40    TargetDanceability(f32),
41    MinDurationMs(i32),
42    MaxDurationMs(i32),
43    TargetDurationMs(i32),
44    MinEnergy(f32),
45    MaxEnergy(f32),
46    TargetEnergy(f32),
47    MinInstrumentalness(f32),
48    MaxInstrumentalness(f32),
49    TargetInstrumentalness(f32),
50    MinKey(i32),
51    MaxKey(i32),
52    TargetKey(i32),
53    MinLiveness(f32),
54    MaxLiveness(f32),
55    TargetLiveness(f32),
56    MinLoudness(f32),
57    MaxLoudness(f32),
58    TargetLoudness(f32),
59    MinMode(i32),
60    MaxMode(i32),
61    TargetMode(i32),
62    MinPopularity(i32),
63    MaxPopularity(i32),
64    TargetPopularity(i32),
65    MinSpeechiness(f32),
66    MaxSpeechiness(f32),
67    TargetSpeechiness(f32),
68    MinTempo(f32),
69    MaxTempo(f32),
70    TargetTempo(f32),
71    MinTimeSignature(i32),
72    MaxTimeSignature(i32),
73    TargetTimeSignature(i32),
74    MinValence(f32),
75    MaxValence(f32),
76    TargetValence(f32),
77}
78
79impl RecommendationsAttribute {
80    /// Obtains the value of the enum as a String, which may be helpful when
81    /// serializing it.
82    #[must_use]
83    pub fn value_string(&self) -> String {
84        use RecommendationsAttribute::*;
85
86        match self {
87            MinAcousticness(x)
88            | MaxAcousticness(x)
89            | TargetAcousticness(x)
90            | MinDanceability(x)
91            | MaxDanceability(x)
92            | TargetDanceability(x)
93            | MinEnergy(x)
94            | MaxEnergy(x)
95            | TargetEnergy(x)
96            | MinInstrumentalness(x)
97            | MaxInstrumentalness(x)
98            | TargetInstrumentalness(x)
99            | MinLiveness(x)
100            | MaxLiveness(x)
101            | TargetLiveness(x)
102            | MinLoudness(x)
103            | MaxLoudness(x)
104            | TargetLoudness(x)
105            | MinTempo(x)
106            | MaxTempo(x)
107            | TargetTempo(x)
108            | MinSpeechiness(x)
109            | MaxSpeechiness(x)
110            | TargetSpeechiness(x)
111            | MinValence(x)
112            | MaxValence(x)
113            | TargetValence(x) => x.to_string(),
114            MinDurationMs(x)
115            | MaxDurationMs(x)
116            | TargetDurationMs(x)
117            | MinPopularity(x)
118            | MaxPopularity(x)
119            | TargetPopularity(x)
120            | MinTimeSignature(x)
121            | MaxTimeSignature(x)
122            | TargetTimeSignature(x)
123            | MinMode(x)
124            | MaxMode(x)
125            | TargetMode(x)
126            | MinKey(x)
127            | MaxKey(x)
128            | TargetKey(x) => x.to_string(),
129        }
130    }
131}