sc_api/
data.rs

1use serde::{Deserialize, Serialize};
2use serde_json::{Map, Value};
3
4
5#[derive(Deserialize, Serialize, Debug)]
6pub struct RegionId(pub String);
7
8impl From<String> for RegionId {
9    fn from(s: String) -> Self {
10        Self(s)
11    }
12}
13
14impl From<&str> for RegionId {
15    fn from(s: &str) -> Self {
16        Self(s.to_string())
17    }
18}
19
20impl ToString for RegionId {
21    fn to_string(&self) -> String {
22        self.0.clone()
23    }
24}
25
26#[derive(Deserialize, Serialize, Debug)]
27pub struct Region {
28    pub id: RegionId,
29    pub name: String,
30}
31
32#[derive(Deserialize, Serialize, Debug)]
33pub struct ItemId(pub String);
34
35impl ToString for ItemId {
36    fn to_string(&self) -> String {
37        self.0.clone()
38    }
39}
40
41impl From<String> for ItemId {
42    fn from(s: String) -> Self {
43        Self(s)
44    }
45}
46
47impl From<&str> for ItemId {
48    fn from(s: &str) -> Self {
49        Self(s.to_string())
50    }
51}
52
53#[derive(Deserialize, Serialize, Debug)]
54pub struct AuctionPriceHistory {
55    pub total: i64,
56    pub prices: Vec<PriceEntry>,
57}
58
59#[derive(Deserialize, Serialize, Debug)]
60pub struct PriceEntry {
61    pub amount: i32,
62    pub price: i32,
63    pub time: String,
64}
65
66#[derive(Deserialize, Serialize, Debug)]
67#[serde(rename_all = "camelCase")]
68pub struct Lot {
69    pub item_id: ItemId,
70
71    pub start_price: i64,
72
73    pub current_price: Option<i64>,
74
75    pub buyout_price: i64,
76
77    pub start_time: String,
78
79    pub end_time: String,
80
81    pub additional: Map<String, Value>,
82}
83
84#[derive(Deserialize, Serialize, Debug)]
85pub struct AuctionLots {
86    pub total: i64,
87    pub lots: Vec<Lot>,
88}
89
90#[derive(Deserialize, Serialize, Debug)]
91pub struct CharacterId(pub String);
92
93impl ToString for CharacterId {
94    fn to_string(&self) -> String {
95        self.0.clone()
96    }
97}
98
99impl From<String> for CharacterId {
100    fn from(s: String) -> Self {
101        Self(s)
102    }
103}
104
105impl From<&str> for CharacterId {
106    fn from(s: &str) -> Self {
107        Self(s.to_string())
108    }
109}
110
111#[derive(Deserialize, Serialize, Debug)]
112#[serde(rename_all = "camelCase")]
113pub struct CharacterMetaInfo {
114    pub id: CharacterId,
115    pub name: String,
116    pub creation_time: String,
117}
118
119#[derive(Deserialize, Serialize, Debug)]
120pub struct ClanId(pub String);
121
122impl ToString for ClanId {
123    fn to_string(&self) -> String {
124        self.0.clone()
125    }
126}
127
128impl From<String> for ClanId {
129    fn from(s: String) -> Self {
130        Self(s)
131    }
132}
133
134impl From<&str> for ClanId {
135    fn from(s: &str) -> Self {
136        Self(s.to_string())
137    }
138}
139
140#[derive(Deserialize, Serialize, Debug)]
141#[serde(rename_all = "camelCase")]
142pub struct ClanInfo {
143    pub id: ClanId,
144    pub name: String,
145    pub tag: String,
146    pub level: i32,
147    pub level_points: i32,
148    pub registration_time: String,
149    pub alliance: Option<String>,
150    pub description: String,
151    pub leader: String,
152    pub member_count: i32,
153}
154
155#[derive(Deserialize, Serialize, Debug)]
156pub enum Rank {
157    RECRUIT,
158    COMMONER,
159    SOLDIER,
160    SERGEANT,
161    OFFICER,
162    COLONEL,
163    LEADER,
164}
165
166#[derive(Deserialize, Serialize, Debug)]
167#[serde(rename_all = "camelCase")]
168pub struct ClanMember {
169    pub name: String,
170    pub rank: Rank,
171    pub join_time: String,
172}
173
174#[derive(Deserialize, Serialize, Debug)]
175pub struct CharacterClanInfo {
176    pub info: ClanInfo,
177    pub member: ClanMember,
178}
179
180#[derive(Deserialize, Serialize, Debug)]
181pub struct Character {
182    pub information: CharacterMetaInfo,
183    pub clan: Option<CharacterClanInfo>,
184}
185
186#[derive(Deserialize, Serialize, Debug)]
187pub struct ClanMembers(pub Vec<ClanMember>);
188
189#[derive(Deserialize, Serialize, Debug)]
190#[serde(rename_all = "camelCase")]
191pub struct ClansList {
192    pub total_clans: i32,
193    pub data: Vec<ClanInfo>,
194}
195
196#[derive(Deserialize, Serialize, Debug)]
197#[serde(rename_all = "camelCase")]
198pub struct EmissionInformation {
199    pub current_start: String,
200    pub previous_start: String,
201    pub previous_end: String,
202}
203
204#[derive(Deserialize, Serialize, Debug)]
205pub struct FriendsList(pub Vec<String>);
206
207pub enum Sort {
208    TimeCreated,
209    TimeLeft,
210    CurrentPrice,
211    BuyoutPrice,
212}
213
214impl ToString for Sort {
215    fn to_string(&self) -> String {
216        match self {
217            Sort::TimeCreated => "time_created",
218            Sort::TimeLeft => "time_left",
219            Sort::CurrentPrice => "current_price",
220            Sort::BuyoutPrice => "buyout_price",
221        }.to_string()
222    }
223}
224
225pub enum Order {
226    Asc,
227    Desc,
228}
229
230impl ToString for Order {
231    fn to_string(&self) -> String {
232        match self {
233            Order::Asc => "asc",
234            Order::Desc => "desc",
235        }.to_string()
236    }
237}