tosho_mplus/proto/
enums.rs

1//! A module containing information related to enums used in the library.
2//!
3//! If something is missing, please [open an issue](https://github.com/noaione/tosho-mango/issues/new/choose) or a [pull request](https://github.com/noaione/tosho-mango/compare).
4
5use tosho_macros::EnumName;
6
7/// The error action or error code of the request.
8#[derive(
9    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
10)]
11pub enum ErrorAction {
12    /// Some default or other unknown error.
13    Default = 0,
14    /// The request is unauthorized.
15    Unauthorized = 1,
16    /// Server is under maintenance.
17    Maintenance = 2,
18    /// The request is blocked by GeoIP.
19    GeoIPBlocked = 3,
20    /// An error has occurred.
21    #[invalid_enum]
22    Unrecognized = -1,
23}
24
25/// Enum for the available language in the source.
26#[derive(
27    Clone,
28    Copy,
29    Debug,
30    PartialEq,
31    Eq,
32    Hash,
33    PartialOrd,
34    Ord,
35    EnumName,
36    ::tosho_macros::ProstEnumUnrecognized,
37)]
38pub enum Language {
39    /// English language.
40    English = 0,
41    /// Spanish language.
42    Spanish = 1,
43    /// French language.
44    French = 2,
45    /// Indonesian language.
46    Indonesian = 3,
47    /// Brazilian Portuguese language.
48    BrazilianPortuguese = 4,
49    /// Russian language.
50    Russian = 5,
51    /// Thai language.
52    Thai = 6,
53    /// German language.
54    German = 7,
55    /// Italian language.
56    ///
57    /// This language is currently unused.
58    Italian = 8,
59    /// Vietnamese language.
60    Vietnamese = 9,
61    /// Unknown language.
62    #[invalid_enum]
63    Unrecognized = -1,
64}
65
66impl Language {
67    /// Get the pretty name of the language.
68    ///
69    /// # Examples
70    /// ```rust
71    /// use tosho_mplus::proto::Language;
72    ///
73    /// let pt_br = Language::BrazilianPortuguese;
74    ///
75    /// assert_eq!(pt_br.pretty_name(), "Brazilian Portuguese");
76    /// ```
77    pub fn pretty_name(&self) -> String {
78        pretty_name_fmt(self.to_name(), " ")
79    }
80
81    /// Get the language code for the language.
82    ///
83    /// # Examples
84    /// ```rust
85    /// use tosho_mplus::proto::Language;
86    ///
87    /// let english = Language::English;
88    /// assert_eq!(english.as_language_code(), "eng");
89    /// ```
90    pub fn as_language_code(&self) -> &'static str {
91        match self {
92            Language::English => "eng",
93            Language::Spanish => "spa",
94            Language::French => "fra",
95            Language::Indonesian => "ind",
96            Language::BrazilianPortuguese => "ptb",
97            Language::Russian => "rus",
98            Language::Thai => "tha",
99            Language::German => "deu",
100            Language::Italian => "ita",
101            Language::Vietnamese => "vie",
102            Language::Unrecognized => "unknown",
103        }
104    }
105
106    /// Get the country code for the language.
107    ///
108    /// # Examples
109    /// ```rust
110    /// use tosho_mplus::proto::Language;
111    ///
112    /// let english = Language::English;
113    /// assert_eq!(english.as_country_code(), "en");
114    /// ```
115    pub fn as_country_code(&self) -> &'static str {
116        match self {
117            Language::English => "en",
118            Language::Spanish => "es",
119            Language::French => "fr",
120            Language::Indonesian => "in",
121            Language::BrazilianPortuguese => "pt",
122            Language::Russian => "ru",
123            Language::Thai => "th",
124            Language::German => "de",
125            Language::Italian => "it",
126            Language::Vietnamese => "vi",
127            Language::Unrecognized => "unknown",
128        }
129    }
130}
131
132/// The title update status
133#[derive(
134    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
135)]
136pub enum TitleUpdateStatus {
137    /// No update available.
138    None = 0,
139    /// New title.
140    New = 1,
141    /// Updated chapter available.
142    Updated = 2,
143    /// Re-edition/Re-release chapter available.
144    ReEdition = 3,
145    /// Update for creator manga
146    Creator = 4,
147    /// An error has occurred.
148    #[invalid_enum]
149    Unrecognized = -1,
150}
151
152/// The page type
153#[derive(
154    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
155)]
156pub enum PageType {
157    /// Single page
158    Single = 0,
159    /// Left-side of the page (on double page)
160    Left = 1,
161    /// Right-side of the page (on double page)
162    Right = 2,
163    /// A merged spread page
164    Double = 3,
165    /// An error has occurred.
166    #[invalid_enum]
167    Unrecognized = -1,
168}
169
170/// The chapter type
171#[derive(
172    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
173)]
174pub enum ChapterType {
175    /// Latest chapter
176    Latest = 0,
177    /// Current chapter in a sequence (not latest)
178    Sequence = 1,
179    /// No sequence, just a chapter
180    NoSequence = 2,
181    /// An error has occurred.
182    #[invalid_enum]
183    Unrecognized = -1,
184}
185
186/// Enums for update profile result
187#[derive(
188    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
189)]
190pub enum UpdateProfileResult {
191    /// Profile updated successfully
192    Success = 0,
193    /// Another profile with the same name already exists
194    Duplicate = 1,
195    /// The name contains disallowed words
196    BadName = 2,
197    /// An error has occurred.
198    #[invalid_enum]
199    Unrecognized = -1,
200}
201
202/// Feedback type
203#[derive(
204    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
205)]
206pub enum FeedbackType {
207    /// Feedback is a question (original poster)
208    Question = 0,
209    /// Feedback is a answer to a question
210    Answer = 1,
211    /// An error has occurred.
212    #[invalid_enum]
213    Unrecognized = -1,
214}
215
216/// Plan offer type
217#[derive(
218    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
219)]
220pub enum PlanOfferType {
221    /// No offer
222    Free = 0,
223    /// Introductory offer to the plan
224    Introductory = 1,
225    /// Promotional offer to the plan
226    Promotional = 2,
227    /// An error has occurred.
228    #[invalid_enum]
229    Unrecognized = -1,
230}
231
232/// Title release schedule
233#[derive(
234    Clone,
235    Copy,
236    Debug,
237    PartialEq,
238    Eq,
239    Hash,
240    PartialOrd,
241    Ord,
242    EnumName,
243    ::tosho_macros::ProstEnumUnrecognized,
244)]
245pub enum TitleReleaseSchedule {
246    /// No schedule
247    None = 0,
248    /// Daily/everyday schedule
249    Daily = 1,
250    /// Weekly schedule
251    Weekly = 2,
252    /// Bi-weekly schedule
253    BiWeekly = 3,
254    /// Monthly schedule
255    Monthly = 4,
256    /// Bi-monthly schedule
257    BiMonthly = 5,
258    /// Tri-monthly schedule
259    TriMonthly = 6,
260    /// Other schedule
261    Other = 7,
262    /// Series is completed
263    Completed = 8,
264    /// An error has occurred.
265    #[invalid_enum]
266    Unrecognized = -1,
267}
268
269impl TitleReleaseSchedule {
270    /// Get the pretty name of the release schedule.
271    ///
272    /// # Examples
273    /// ```rust
274    /// use tosho_mplus::proto::TitleReleaseSchedule;
275    ///
276    /// let biweekly = TitleReleaseSchedule::BiWeekly;
277    ///
278    /// assert_eq!(biweekly.pretty_name(), "Bi-Weekly");
279    /// ```
280    pub fn pretty_name(&self) -> String {
281        pretty_name_fmt(self.to_name(), "-")
282    }
283}
284
285/// Title rating
286#[derive(
287    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
288)]
289pub enum TitleRating {
290    /// All ages rating
291    AllAges = 0,
292    /// Teen rating
293    Teen = 1,
294    /// Teen+ rating
295    TeenPlus = 2,
296    /// Mature rating
297    Mature = 3,
298    /// An error has occurred.
299    #[invalid_enum]
300    Unrecognized = -1,
301}
302
303fn pretty_name_fmt(name: &str, sep: &str) -> String {
304    let split_at_upper: Vec<_> = name.match_indices(char::is_uppercase).collect();
305    let mut splitted_name: Vec<&str> = vec![];
306    split_at_upper
307        .iter()
308        .enumerate()
309        .for_each(|(i, (start, _))| {
310            if i == 0 {
311                let data = &name[..*start];
312                if !data.is_empty() {
313                    splitted_name.push(data);
314                }
315            }
316            let next_start = split_at_upper.get(i + 1);
317            match next_start {
318                Some((end, _)) => splitted_name.push(&name[*start..*end]),
319                None => splitted_name.push(&name[*start..]),
320            }
321        });
322
323    let mut merge_back = splitted_name.join(sep);
324    let some_words = &["The", "A", "An"];
325    some_words.iter().for_each(|&word| {
326        merge_back = merge_back.replace(&format!(" {word}"), &format!(" {}", word.to_lowercase()));
327    });
328
329    if splitted_name.len() > 1 {
330        match splitted_name[0] {
331            "e" => merge_back = merge_back.replacen("e ", "e-", 1),
332            "D" => merge_back = merge_back.replacen("D ", "Digital ", 1),
333            _ => (),
334        }
335    }
336    if merge_back.contains('_') {
337        merge_back = merge_back.replace('_', " ");
338    }
339    merge_back
340}
341
342/// Chapter position in the series chapters list group
343///
344/// This is a custom enum that does not exist originally in the API.
345/// Made to make it easier to understand the position of the chapter in the series.
346#[derive(
347    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::tosho_macros::ProstEnumUnrecognized,
348)]
349pub enum ChapterPosition {
350    /// Chapter located in the middle of the chapter list (usually need subs or tickets)
351    Middle = 0,
352    /// Chapter located in first chapter list (usually free)
353    First = 1,
354    /// Chapter located in last chapter list (usually free)
355    Last = 2,
356    /// An error has occurred.
357    #[invalid_enum]
358    Unrecognized = -1,
359}