1use std::fmt::Display;
2
3#[derive(Debug)]
4pub enum RankingType {
5 All,
6 Airing,
7 Upcoming,
8 TV,
9 OVA,
10 Movie,
11 Special,
12 ByPopularity,
13 Favorite,
14}
15
16impl Display for RankingType {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 let me = match self {
19 Self::Favorite => "favorite".to_owned(),
20 Self::TV => "tv".to_owned(),
21 Self::Airing => "airing".to_owned(),
22 Self::Upcoming => "upcoming".to_owned(),
23 Self::Special => "special".to_owned(),
24 Self::ByPopularity => "bypopularity".to_owned(),
25 Self::Movie => "movie".to_owned(),
26 Self::OVA => "ova".to_owned(),
27 Self::All => "all".to_owned(),
28 };
29 write!(f, "{}", me)
30 }
31}
32
33#[derive(Debug)]
34pub enum Season {
35 Winter,
36 Spring,
37 Summer,
38 Fall,
39}
40
41impl Display for Season {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 let me = match self {
44 Self::Winter => "winter".to_owned(),
45 Self::Spring => "spring".to_owned(),
46 Self::Summer => "summer".to_owned(),
47 Self::Fall => "fall".to_owned(),
48 };
49 write!(f, "{}", me)
50 }
51}
52
53#[derive(Debug)]
54pub enum Status {
55 Watching,
56 Completed,
57 OnHold,
58 Dropped,
59 PlanToWatch,
60}
61
62impl Display for Status {
63 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64 let me = match self {
65 Self::Watching => "watching".to_owned(),
66 Self::Completed => "completed".to_owned(),
67 Self::OnHold => "on_hold".to_owned(),
68 Self::Dropped => "dropped".to_owned(),
69 Self::PlanToWatch => "plan_to_watch".to_owned(),
70 };
71 write!(f, "{}", me)
72 }
73}
74
75pub trait Params {
76 fn get_params<'a>(self) -> Vec<(&'a str, String)>;
77}
78
79#[derive(Debug, Default)]
80pub struct StatusUpdate {
81 status: Option<Status>,
82 is_rewatching: Option<bool>,
83 score: Option<u8>,
84 num_watched_episodes: Option<u32>,
85 priority: Option<u8>,
86 num_times_rewatched: Option<u32>,
87 rewatch_value: Option<u8>,
88 tags: Option<Vec<String>>,
89 comments: Option<String>,
90}
91
92impl StatusUpdate {
93 pub fn new() -> Self {
94 Self::default()
95 }
96
97 pub fn status(&mut self, status: Status) {
98 self.status = Some(status);
99 }
100
101 pub fn is_rewatching(&mut self, is_rewatching: bool) {
102 self.is_rewatching = Some(is_rewatching);
103 }
104
105 pub fn score(&mut self, score: u8) {
106 self.score = Some(score);
107 }
108 pub fn num_watched_episodes(&mut self, num_watched_episodes: u32) {
109 self.num_watched_episodes = Some(num_watched_episodes);
110 }
111 pub fn priority(&mut self, priority: u8) {
112 self.priority = Some(priority);
113 }
114 pub fn num_times_rewatched(&mut self, num_times_rewatched: u32) {
115 self.num_times_rewatched = Some(num_times_rewatched);
116 }
117 pub fn rewatch_value(&mut self, rewatch_value: u8) {
118 self.rewatch_value = Some(rewatch_value);
119 }
120 pub fn tags(&mut self, tags: Vec<String>) {
121 self.tags = Some(tags);
122 }
123 pub fn comments(&mut self, comments: &str) {
124 self.comments = Some(comments.to_owned());
125 }
126}
127
128impl Params for StatusUpdate {
129 fn get_params<'a>(self) -> Vec<(&'a str, String)> {
130 let mut params = vec![];
131 if let Some(s) = self.status {
132 params.push(("status", s.to_string()));
133 }
134 if let Some(rw) = self.is_rewatching {
135 params.push(("is_rewatching", rw.to_string()));
136 }
137 if let Some(t) = self.score {
138 params.push(("score", t.to_string()));
139 }
140 if let Some(t) = self.num_watched_episodes {
141 params.push(("num_watched_episodes", t.to_string()));
142 }
143 if let Some(t) = self.priority {
144 params.push(("priority", t.to_string()));
145 }
146 if let Some(t) = self.num_times_rewatched {
147 params.push(("num_times_rewatched", t.to_string()));
148 }
149 if let Some(t) = self.rewatch_value {
150 params.push(("rewatch_value", t.to_string()));
151 }
152 if let Some(t) = self.tags {
153 params.push(("tags", t.join(",")));
154 }
155 if let Some(t) = self.comments {
156 params.push(("comments", t));
157 }
158
159 params
160 }
161}
162
163pub struct StatusBuilder {
164 status: Option<Status>,
165 is_rewatching: Option<bool>,
166 score: Option<u8>,
167 num_watched_episodes: Option<u32>,
168 priority: Option<u8>,
169 num_times_rewatched: Option<u32>,
170 rewatch_value: Option<u8>,
171 tags: Option<Vec<String>>,
172 comments: Option<String>,
173}
174
175impl Default for StatusBuilder {
176 fn default() -> Self {
177 Self::new()
178 }
179}
180
181impl StatusBuilder {
182 pub fn new() -> Self {
183 StatusBuilder {
184 status: None,
185 is_rewatching: None,
186 score: None,
187 num_watched_episodes: None,
188 priority: None,
189 num_times_rewatched: None,
190 rewatch_value: None,
191 tags: None,
192 comments: None,
193 }
194 }
195
196 pub fn status(mut self, status: impl Into<Option<Status>>) -> Self {
197 self.status = status.into();
198 self
199 }
200
201 pub fn is_rewatching(mut self, is_rewatching: impl Into<Option<bool>>) -> Self {
202 self.is_rewatching = is_rewatching.into();
203 self
204 }
205
206 pub fn score(mut self, score: impl Into<Option<u8>>) -> Self {
207 self.score = score.into();
208 self
209 }
210
211 pub fn num_watched_episodes(mut self, num_watched_episodes: impl Into<Option<u32>>) -> Self {
212 self.num_watched_episodes = num_watched_episodes.into();
213 self
214 }
215
216 pub fn priority(mut self, priority: impl Into<Option<u8>>) -> Self {
217 self.priority = priority.into();
218 self
219 }
220
221 pub fn num_times_rewatched(mut self, num_times_rewatched: impl Into<Option<u32>>) -> Self {
222 self.num_times_rewatched = num_times_rewatched.into();
223 self
224 }
225
226 pub fn rewatch_value(mut self, rewatch_value: impl Into<Option<u8>>) -> Self {
227 self.rewatch_value = rewatch_value.into();
228 self
229 }
230
231 pub fn tags(mut self, tags: impl Into<Option<Vec<String>>>) -> Self {
232 self.tags = tags.into();
233 self
234 }
235
236 pub fn comments(mut self, comments: impl Into<Option<String>>) -> Self {
237 self.comments = comments.into();
238 self
239 }
240
241 pub fn build(self) -> StatusUpdate {
242 StatusUpdate {
243 status: self.status,
244 is_rewatching: self.is_rewatching,
245 score: self.score,
246 num_watched_episodes: self.num_watched_episodes,
247 priority: self.priority,
248 num_times_rewatched: self.num_times_rewatched,
249 rewatch_value: self.rewatch_value,
250 tags: self.tags,
251 comments: self.comments,
252 }
253 }
254}