1#![allow(clippy::derive_partial_eq_without_eq)]
6
7use std::str::FromStr;
8
9use tosho_macros::AutoGetter;
10
11use crate::helper::SubscriptionPlan;
12
13use super::enums::{ErrorAction, Language};
14
15#[derive(Clone, PartialEq, ::prost::Message)]
17pub struct PopupButton {
18 #[prost(string, optional, tag = "1")]
20 text: ::core::option::Option<::prost::alloc::string::String>,
21 }
24
25#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
27pub struct PopupMessage {
28 #[prost(string, optional, tag = "1")]
30 #[skip_field]
31 subject: ::core::option::Option<::prost::alloc::string::String>,
32 #[prost(string, optional, tag = "2")]
34 #[skip_field]
35 body: ::core::option::Option<::prost::alloc::string::String>,
36 #[prost(message, optional, tag = "3")]
38 ok_button: ::core::option::Option<PopupButton>,
39 #[prost(message, optional, tag = "4")]
41 neutral_button: ::core::option::Option<PopupButton>,
42 #[prost(message, optional, tag = "5")]
44 cancel_button: ::core::option::Option<PopupButton>,
45 #[prost(enumeration = "Language", tag = "6")]
47 #[skip_field]
48 language: i32,
49}
50
51impl PopupMessage {
52 pub fn as_string(&self) -> String {
54 let mut message = String::new();
55 if let Some(subject) = &self.subject {
56 message.push_str(subject);
57 message.push_str(": ");
58 }
59 if let Some(body) = &self.body {
60 message.push_str(body);
61 }
62 message
63 }
64}
65
66#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
68pub struct ErrorResponse {
69 #[prost(enumeration = "ErrorAction", tag = "1")]
71 #[skip_field]
72 action: i32,
73 #[prost(message, optional, tag = "2")]
75 english_popup: ::core::option::Option<PopupMessage>,
76 #[prost(message, optional, tag = "3")]
78 spanish_popup: ::core::option::Option<PopupMessage>,
79 #[prost(string, optional, tag = "4")]
81 #[skip_field]
82 debug_message: ::core::option::Option<::prost::alloc::string::String>,
83 #[prost(message, repeated, tag = "5")]
85 other_popups: ::prost::alloc::vec::Vec<PopupMessage>,
86}
87
88impl ErrorResponse {
89 pub fn as_string(&self) -> String {
91 let popup_message = self.english_popup.as_ref().map(|popup| popup.as_string());
92 match self.action() {
93 ErrorAction::Default => {
94 let mut message = String::new();
95 message.push_str("An error occurred");
96 if let Some(popup_message) = popup_message {
97 message.push_str(&format!(": {popup_message}"));
98 }
99 if let Some(debug_message) = &self.debug_message {
100 message.push_str(&format!("\nDebug: {debug_message}"));
101 }
102 message
103 }
104 ErrorAction::Unauthorized => {
105 let mut message = String::new();
106 message.push_str("You are not authorized to access this resource");
107 if let Some(debug_message) = &self.debug_message {
108 message.push_str(&format!("\nDebug: {debug_message}"));
109 }
110 message
111 }
112 ErrorAction::Maintenance => {
113 let mut message = String::new();
114 message.push_str("Server is under maintenance");
115 if let Some(debug_message) = &self.debug_message {
116 message.push_str(&format!("\nDebug: {debug_message}"));
117 }
118 message
119 }
120 ErrorAction::GeoIPBlocked => {
121 let mut message = String::new();
122 message.push_str("Your request is blocked by GeoIP");
123 if let Some(debug_message) = &self.debug_message {
124 message.push_str(&format!("\nDebug: {debug_message}"));
125 }
126 message
127 }
128 ErrorAction::Unrecognized => {
129 let mut message = String::new();
130 message.push_str("An unknown error occurred");
131 if let Some(debug_message) = &self.debug_message {
132 message.push_str(&format!("\nDebug: {debug_message}"));
133 }
134 message
135 }
136 }
137 }
138}
139
140#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
142pub struct Banner {
143 #[prost(string, tag = "1")]
145 image: ::prost::alloc::string::String,
146 #[prost(uint64, optional, tag = "3")]
148 #[skip_field]
149 id: Option<u64>,
150 #[prost(uint32, optional, tag = "4")]
152 #[skip_field]
153 width: Option<u32>,
154 #[prost(uint32, optional, tag = "5")]
156 #[skip_field]
157 height: Option<u32>,
158}
159
160#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
162pub struct Tag {
163 #[prost(string, tag = "1")]
165 name: ::prost::alloc::string::String,
166 #[prost(string, tag = "2")]
168 slug: ::prost::alloc::string::String,
169}
170
171#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
173pub struct Label {
174 #[prost(uint64, tag = "1")]
176 id: u64,
177 #[prost(string, tag = "2")]
179 description: ::prost::alloc::string::String,
180}
181
182#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
184pub struct PublisherNews {
185 #[prost(uint64, tag = "1")]
187 news_id: u64,
188 #[prost(uint64, tag = "2")]
190 publisher_id: u64,
191 #[prost(string, tag = "3")]
193 name: ::prost::alloc::string::String,
194 #[prost(string, tag = "4")]
196 title: ::prost::alloc::string::String,
197 #[prost(string, tag = "5")]
199 content: ::prost::alloc::string::String,
200 #[prost(uint64, tag = "6")]
202 published_at: u64,
203}
204
205#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
207pub struct PublisherItem {
208 #[prost(message, optional, tag = "1")]
210 banner: ::core::option::Option<Banner>,
211 #[prost(message, optional, tag = "2")]
213 news: ::core::option::Option<PublisherNews>,
214}
215
216#[derive(Clone, AutoGetter, PartialEq, Copy, ::prost::Message)]
218pub struct AvailableLanguages {
219 #[prost(enumeration = "Language", tag = "1")]
221 #[skip_field]
222 language: i32,
223 #[prost(uint64, tag = "2")]
225 titles_count: u64,
226}
227
228#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
230pub struct Languages {
231 #[prost(enumeration = "Language", tag = "1")]
233 #[skip_field]
234 language: i32,
235 #[prost(enumeration = "Language", optional, tag = "2")]
237 #[skip_field]
238 content_language: ::core::option::Option<i32>,
239 #[prost(enumeration = "Language", optional, tag = "3")]
243 #[skip_field]
244 content_language_secondary: ::core::option::Option<i32>,
245 #[prost(enumeration = "Language", optional, tag = "4")]
249 #[skip_field]
250 content_language_tertiary: ::core::option::Option<i32>,
251 #[prost(message, repeated, tag = "5")]
253 availables: ::prost::alloc::vec::Vec<AvailableLanguages>,
254}
255
256impl Languages {
257 pub fn content_languages(&self) -> Language {
259 match (
260 self.content_language_tertiary,
261 self.content_language_secondary,
262 self.content_language,
263 ) {
264 (Some(_), _, _) => self.content_language_tertiary(),
265 (_, Some(_), _) => self.content_language_secondary(),
266 (_, _, Some(_)) => self.content_language(),
267 _ => Language::English,
268 }
269 }
270}
271
272#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
274pub struct SubscriptionOfferAndroid {
275 #[prost(string, tag = "1")]
277 tag: ::prost::alloc::string::String,
278}
279
280#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
282pub struct SubscriptionOfferApple {
283 #[prost(enumeration = "super::PlanOfferType", tag = "1")]
285 #[skip_field]
286 kind: i32,
287 #[prost(string, tag = "2")]
289 signature: ::prost::alloc::string::String,
290 #[prost(string, tag = "3")]
292 key: ::prost::alloc::string::String,
293 #[prost(string, tag = "4")]
295 nonce: ::prost::alloc::string::String,
296 #[prost(string, tag = "5")]
298 timestamp: ::prost::alloc::string::String,
299 #[prost(string, tag = "6")]
301 identifier: ::prost::alloc::string::String,
302}
303
304#[derive(Clone, AutoGetter, PartialEq, ::prost::Message)]
306pub struct Plan {
307 #[prost(string, tag = "1")]
309 #[skip_field]
310 name: ::prost::alloc::string::String,
311 #[prost(string, tag = "2")]
313 description: ::prost::alloc::string::String,
314 #[prost(string, tag = "3")]
316 product_id: ::prost::alloc::string::String,
317 #[prost(message, optional, tag = "4")]
319 apple_offer: ::core::option::Option<SubscriptionOfferApple>,
320 #[prost(message, repeated, tag = "5")]
322 android_offer: ::prost::alloc::vec::Vec<SubscriptionOfferAndroid>,
323}
324
325impl Plan {
326 pub fn name(&self) -> SubscriptionPlan {
331 match SubscriptionPlan::from_str(&self.name) {
332 Ok(plan) => plan,
333 Err(_) => SubscriptionPlan::Basic,
334 }
335 }
336}