1use chrono::{serde::ts_seconds, DateTime, Utc};
2use serde::Deserialize;
3use torn_api_macros::IntoOwned;
4
5use crate::de_util;
6
7#[derive(Debug, Clone, Deserialize)]
8pub enum OnlineStatus {
9 Online,
10 Offline,
11 Idle,
12}
13
14#[derive(Debug, Clone, Deserialize)]
15pub struct LastAction {
16 #[serde(with = "ts_seconds")]
17 pub timestamp: DateTime<Utc>,
18 pub status: OnlineStatus,
19}
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
22pub enum State {
23 Okay,
24 Traveling,
25 Hospital,
26 Abroad,
27 Jail,
28 Federal,
29 Fallen,
30}
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
33#[serde(rename_all = "lowercase")]
34pub enum StateColour {
35 Green,
36 Red,
37 Blue,
38}
39
40#[derive(Debug, IntoOwned, Deserialize)]
41pub struct Status<'a> {
42 pub description: &'a str,
43 #[serde(deserialize_with = "de_util::empty_string_is_none")]
44 pub details: Option<&'a str>,
45 #[serde(rename = "color")]
46 pub colour: StateColour,
47 pub state: State,
48 #[serde(deserialize_with = "de_util::zero_date_is_none")]
49 pub until: Option<DateTime<Utc>>,
50}
51
52#[derive(Debug, Clone, Deserialize)]
53pub struct Territory {
54 pub sector: i16,
55 pub size: i16,
56 pub density: i16,
57 pub daily_respect: i16,
58 pub faction: i32,
59
60 #[cfg(feature = "decimal")]
61 #[serde(deserialize_with = "de_util::string_or_decimal")]
62 pub coordinate_x: rust_decimal::Decimal,
63
64 #[cfg(feature = "decimal")]
65 #[serde(deserialize_with = "de_util::string_or_decimal")]
66 pub coordinate_y: rust_decimal::Decimal,
67}
68
69#[derive(Debug, Clone, Copy, Deserialize)]
70pub enum AttackResult {
71 Attacked,
72 Mugged,
73 Hospitalized,
74 Lost,
75 Arrested,
76 Escape,
77 Interrupted,
78 Assist,
79 Timeout,
80 Stalemate,
81 Special,
82 Looted,
83}
84
85#[derive(Debug, Clone, Deserialize)]
86pub struct Attack<'a> {
87 pub code: &'a str,
88 #[serde(with = "ts_seconds")]
89 pub timestamp_started: DateTime<Utc>,
90 #[serde(with = "ts_seconds")]
91 pub timestamp_ended: DateTime<Utc>,
92
93 #[serde(deserialize_with = "de_util::empty_string_int_option")]
94 pub attacker_id: Option<i32>,
95 #[serde(deserialize_with = "de_util::empty_string_int_option")]
96 pub attacker_faction: Option<i32>,
97 pub defender_id: i32,
98 #[serde(deserialize_with = "de_util::empty_string_int_option")]
99 pub defender_faction: Option<i32>,
100 pub result: AttackResult,
101
102 #[serde(deserialize_with = "de_util::int_is_bool")]
103 pub stealthed: bool,
104
105 #[cfg(feature = "decimal")]
106 pub respect: rust_decimal::Decimal,
107
108 #[cfg(not(feature = "decimal"))]
109 pub respect: f32,
110}
111
112#[derive(Debug, Clone, Deserialize)]
113pub struct RespectModifiers {
114 pub fair_fight: f32,
115 pub war: f32,
116 pub retaliation: f32,
117 pub group_attack: f32,
118 pub overseas: f32,
119 pub chain_bonus: f32,
120}
121
122#[derive(Debug, Clone, Deserialize)]
123pub struct AttackFull<'a> {
124 pub code: &'a str,
125 #[serde(with = "ts_seconds")]
126 pub timestamp_started: DateTime<Utc>,
127 #[serde(with = "ts_seconds")]
128 pub timestamp_ended: DateTime<Utc>,
129
130 #[serde(deserialize_with = "de_util::empty_string_int_option")]
131 pub attacker_id: Option<i32>,
132 #[serde(deserialize_with = "de_util::empty_string_is_none")]
133 pub attacker_name: Option<&'a str>,
134 #[serde(deserialize_with = "de_util::empty_string_int_option")]
135 pub attacker_faction: Option<i32>,
136 #[serde(
137 deserialize_with = "de_util::empty_string_is_none",
138 rename = "attacker_factionname"
139 )]
140 pub attacker_faction_name: Option<&'a str>,
141
142 pub defender_id: i32,
143 pub defender_name: &'a str,
144 #[serde(deserialize_with = "de_util::empty_string_int_option")]
145 pub defender_faction: Option<i32>,
146 #[serde(
147 deserialize_with = "de_util::empty_string_is_none",
148 rename = "defender_factionname"
149 )]
150 pub defender_faction_name: Option<&'a str>,
151
152 pub result: AttackResult,
153
154 #[serde(deserialize_with = "de_util::int_is_bool")]
155 pub stealthed: bool,
156 #[serde(deserialize_with = "de_util::int_is_bool")]
157 pub raid: bool,
158 #[serde(deserialize_with = "de_util::int_is_bool")]
159 pub ranked_war: bool,
160
161 #[cfg(feature = "decimal")]
162 pub respect: rust_decimal::Decimal,
163 #[cfg(feature = "decimal")]
164 pub respect_loss: rust_decimal::Decimal,
165
166 #[cfg(not(feature = "decimal"))]
167 pub respect: f32,
168 #[cfg(not(feature = "decimal"))]
169 pub respect_loss: f32,
170
171 pub modifiers: RespectModifiers,
172}