1 //! All objects related to recommendation
2 
3 use serde::{Deserialize, Serialize};
4 use strum::AsRefStr;
5 
6 use crate::{RecommendationsSeedType, SimplifiedTrack};
7 
8 /// Recommendations object
9 #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
10 pub 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)]
17 pub 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, AsRefStr)]
32 #[serde(rename_all = "snake_case")]
33 #[strum(serialize_all = "snake_case")]
34 pub 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 
79 impl RecommendationsAttribute {
80     /// Obtains the value of the enum as a String, which may be helpful when
81     /// serializing it.
value_string(&self) -> String82     pub fn value_string(&self) -> String {
83         use RecommendationsAttribute::*;
84 
85         match self {
86             MinAcousticness(x) => x.to_string(),
87             MaxAcousticness(x) => x.to_string(),
88             TargetAcousticness(x) => x.to_string(),
89             MinDanceability(x) => x.to_string(),
90             MaxDanceability(x) => x.to_string(),
91             TargetDanceability(x) => x.to_string(),
92             MinDurationMs(x) => x.to_string(),
93             MaxDurationMs(x) => x.to_string(),
94             TargetDurationMs(x) => x.to_string(),
95             MinEnergy(x) => x.to_string(),
96             MaxEnergy(x) => x.to_string(),
97             TargetEnergy(x) => x.to_string(),
98             MinInstrumentalness(x) => x.to_string(),
99             MaxInstrumentalness(x) => x.to_string(),
100             TargetInstrumentalness(x) => x.to_string(),
101             MinKey(x) => x.to_string(),
102             MaxKey(x) => x.to_string(),
103             TargetKey(x) => x.to_string(),
104             MinLiveness(x) => x.to_string(),
105             MaxLiveness(x) => x.to_string(),
106             TargetLiveness(x) => x.to_string(),
107             MinLoudness(x) => x.to_string(),
108             MaxLoudness(x) => x.to_string(),
109             TargetLoudness(x) => x.to_string(),
110             MinMode(x) => x.to_string(),
111             MaxMode(x) => x.to_string(),
112             TargetMode(x) => x.to_string(),
113             MinPopularity(x) => x.to_string(),
114             MaxPopularity(x) => x.to_string(),
115             TargetPopularity(x) => x.to_string(),
116             MinSpeechiness(x) => x.to_string(),
117             MaxSpeechiness(x) => x.to_string(),
118             TargetSpeechiness(x) => x.to_string(),
119             MinTempo(x) => x.to_string(),
120             MaxTempo(x) => x.to_string(),
121             TargetTempo(x) => x.to_string(),
122             MinTimeSignature(x) => x.to_string(),
123             MaxTimeSignature(x) => x.to_string(),
124             TargetTimeSignature(x) => x.to_string(),
125             MinValence(x) => x.to_string(),
126             MaxValence(x) => x.to_string(),
127             TargetValence(x) => x.to_string(),
128         }
129     }
130 }
131