1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
use serde::{Deserialize, Serialize};

// TODO: Specificy how serde should deserialize these...
#[derive(Deserialize, Serialize, Debug)]
pub enum SearchTarget {
    TagsPartial,
    TagsExact,
    TitleAndCaption,
}

impl SearchTarget {
    pub fn as_str(&self) -> &'static str {
        match *self {
            SearchTarget::TagsPartial => "partial_match_for_tags",
            SearchTarget::TagsExact => "exact_match_for_tags",
            SearchTarget::TitleAndCaption => "title_and_caption",
        }
    }

    pub fn map<U, F: FnOnce(Self) -> U>(self, f: F) -> U {
        f(self)
    }
}

#[derive(Deserialize, Serialize, Debug)]
pub enum ContentType {
    #[serde(rename = "illust")]
    Illustration,
    #[serde(rename = "manga")]
    Manga,
    #[serde(rename = "ugoira")]
    Ugoira,
    #[serde(rename = "novel")]
    Novel,
}

impl ContentType {
    pub fn as_str(&self) -> &'static str {
        match *self {
            ContentType::Illustration => "illust",
            ContentType::Manga => "manga",
            ContentType::Ugoira => "ugoira",
            ContentType::Novel => "novel",
        }
    }
}

/// Enum to set publicity param.
#[derive(Debug, Clone, Copy)]
pub enum Publicity {
    Public,
    Private,
}

impl Publicity {
    pub fn as_str(&self) -> &'static str {
        match *self {
            Publicity::Public => "public",
            Publicity::Private => "private",
        }
    }
}

/// Enum to set ranking type param.
#[derive(Debug, Clone, Copy)]
pub enum RankingType {
    All,
    Illust,
    Manga,
    Ugoira,
}

impl RankingType {
    pub fn as_str(&self) -> &'static str {
        match *self {
            RankingType::All => "all",
            RankingType::Illust => "illust",
            RankingType::Manga => "manga",
            RankingType::Ugoira => "ugoira",
        }
    }
}

/// Enum to set ranking mode param.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum RankingMode {
    #[serde(rename = "day")]
    Daily,
    #[serde(rename = "week")]
    Weekly,
    #[serde(rename = "month")]
    Monthly,
    #[serde(rename = "day_male")]
    DayMale,
    #[serde(rename = "day_female")]
    DayFemale,
    #[serde(rename = "week_original")]
    WeekOriginal,
    #[serde(rename = "week_rookie")]
    WeekRookie,
    #[serde(rename = "day_manga")]
    DayManga,
}

impl RankingMode {
    pub fn as_str(&self) -> &'static str {
        match *self {
            RankingMode::Daily => "day",
            RankingMode::Weekly => "week",
            RankingMode::Monthly => "month",
            RankingMode::DayMale => "day_male",
            RankingMode::DayFemale => "day_female",
            RankingMode::WeekOriginal => "week_original",
            RankingMode::WeekRookie => "week_rookie",
            RankingMode::DayManga => "day_manga",
        }
    }
}

/// Enum to set search period param.
#[derive(Debug, Clone, Copy)]
pub enum SearchPeriod {
    All,
    Day,
    Week,
    Month,
}

impl SearchPeriod {
    pub fn as_str(&self) -> &'static str {
        match *self {
            SearchPeriod::All => "all",
            SearchPeriod::Day => "day",
            SearchPeriod::Week => "week",
            SearchPeriod::Month => "month",
        }
    }
}

/// Enum to set search mode param.
#[derive(Debug, Clone, Copy)]
pub enum SearchMode {
    Text,
    Tag,
    ExactTag,
    Caption,
}

impl SearchMode {
    pub fn as_str(&self) -> &'static str {
        match *self {
            SearchMode::Text => "text",
            SearchMode::Tag => "tag",
            SearchMode::ExactTag => "exact_tag",
            SearchMode::Caption => "caption",
        }
    }
}

/// Enum to set search order param.
#[derive(Debug, Clone, Copy)]
pub enum SearchOrder {
    Descending,
    Ascending,
}

impl SearchOrder {
    pub fn as_str(&self) -> &'static str {
        match *self {
            SearchOrder::Descending => "desc",
            SearchOrder::Ascending => "asc",
        }
    }
}

/// Enum to sort search result.
#[derive(Deserialize, Serialize, Debug)]
pub enum SearchSort {
    DateAscending,
    DateDescending,
}

impl SearchSort {
    pub fn as_str(&self) -> &'static str {
        match *self {
            SearchSort::DateAscending => "date_asc",
            SearchSort::DateDescending => "date_desc",
        }
    }
}

#[derive(Deserialize, Serialize, Debug)]
pub enum Duration {
    LastDay,
    LastWeek,
    LastMonth,
}

impl Duration {
    pub fn as_str(&self) -> &'static str {
        match *self {
            Duration::LastDay => "within_last_day",
            Duration::LastWeek => "within_last_week",
            Duration::LastMonth => "within_last_month",
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub enum Visibility {
    #[serde(rename = "public")]
    Public,
    #[serde(rename = "private")]
    Private,
}

impl Visibility {
    pub fn as_str(&self) -> &'static str {
        match *self {
            Visibility::Public => "public",
            Visibility::Private => "private",
        }
    }
}

impl From<bool> for Visibility {
    fn from(x: bool) -> Self {
        match x {
            true => Visibility::Public,
            false => Visibility::Private,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub enum Filter {
    ForiOS,
}

impl Filter {
    pub fn as_str(&self) -> &'static str {
        match *self {
            Filter::ForiOS => "for_ios",
        }
    }
}