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
use chrono::{serde::ts_seconds, DateTime, Utc};
use serde::Deserialize;
use torn_api_macros::IntoOwned;

use crate::de_util;

#[derive(Debug, Clone, Deserialize)]
pub enum OnlineStatus {
    Online,
    Offline,
    Idle,
}

#[derive(Debug, Clone, Deserialize)]
pub struct LastAction {
    #[serde(with = "ts_seconds")]
    pub timestamp: DateTime<Utc>,
    pub status: OnlineStatus,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
pub enum State {
    Okay,
    Traveling,
    Hospital,
    Abroad,
    Jail,
    Federal,
    Fallen,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum StateColour {
    Green,
    Red,
    Blue,
}

#[derive(Debug, IntoOwned, Deserialize)]
pub struct Status<'a> {
    pub description: &'a str,
    #[serde(deserialize_with = "de_util::empty_string_is_none")]
    pub details: Option<&'a str>,
    #[serde(rename = "color")]
    pub colour: StateColour,
    pub state: State,
    #[serde(deserialize_with = "de_util::zero_date_is_none")]
    pub until: Option<DateTime<Utc>>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Territory {
    pub sector: i16,
    pub size: i16,
    pub density: i16,
    pub daily_respect: i16,
    pub faction: i32,

    #[cfg(feature = "decimal")]
    #[serde(deserialize_with = "de_util::string_or_decimal")]
    pub coordinate_x: rust_decimal::Decimal,

    #[cfg(feature = "decimal")]
    #[serde(deserialize_with = "de_util::string_or_decimal")]
    pub coordinate_y: rust_decimal::Decimal,
}

#[derive(Debug, Clone, Copy, Deserialize)]
pub enum AttackResult {
    Attacked,
    Mugged,
    Hospitalized,
    Lost,
    Arrested,
    Escape,
    Interrupted,
    Assist,
    Timeout,
    Stalemate,
    Special,
    Looted,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Attack<'a> {
    pub code: &'a str,
    #[serde(with = "ts_seconds")]
    pub timestamp_started: DateTime<Utc>,
    #[serde(with = "ts_seconds")]
    pub timestamp_ended: DateTime<Utc>,

    #[serde(deserialize_with = "de_util::empty_string_int_option")]
    pub attacker_id: Option<i32>,
    #[serde(deserialize_with = "de_util::empty_string_int_option")]
    pub attacker_faction: Option<i32>,
    pub defender_id: i32,
    #[serde(deserialize_with = "de_util::empty_string_int_option")]
    pub defender_faction: Option<i32>,
    pub result: AttackResult,

    #[serde(deserialize_with = "de_util::int_is_bool")]
    pub stealthed: bool,

    #[cfg(feature = "decimal")]
    pub respect: rust_decimal::Decimal,

    #[cfg(not(feature = "decimal"))]
    pub respect: f32,
}

#[derive(Debug, Clone, Deserialize)]
pub struct RespectModifiers {
    pub fair_fight: f32,
    pub war: f32,
    pub retaliation: f32,
    pub group_attack: f32,
    pub overseas: f32,
    pub chain_bonus: f32,
}

#[derive(Debug, Clone, Deserialize)]
pub struct AttackFull<'a> {
    pub code: &'a str,
    #[serde(with = "ts_seconds")]
    pub timestamp_started: DateTime<Utc>,
    #[serde(with = "ts_seconds")]
    pub timestamp_ended: DateTime<Utc>,

    #[serde(deserialize_with = "de_util::empty_string_int_option")]
    pub attacker_id: Option<i32>,
    #[serde(deserialize_with = "de_util::empty_string_is_none")]
    pub attacker_name: Option<&'a str>,
    #[serde(deserialize_with = "de_util::empty_string_int_option")]
    pub attacker_faction: Option<i32>,
    #[serde(
        deserialize_with = "de_util::empty_string_is_none",
        rename = "attacker_factionname"
    )]
    pub attacker_faction_name: Option<&'a str>,

    pub defender_id: i32,
    pub defender_name: &'a str,
    #[serde(deserialize_with = "de_util::empty_string_int_option")]
    pub defender_faction: Option<i32>,
    #[serde(
        deserialize_with = "de_util::empty_string_is_none",
        rename = "defender_factionname"
    )]
    pub defender_faction_name: Option<&'a str>,

    pub result: AttackResult,

    #[serde(deserialize_with = "de_util::int_is_bool")]
    pub stealthed: bool,
    #[serde(deserialize_with = "de_util::int_is_bool")]
    pub raid: bool,
    #[serde(deserialize_with = "de_util::int_is_bool")]
    pub ranked_war: bool,

    #[cfg(feature = "decimal")]
    pub respect: rust_decimal::Decimal,
    #[cfg(feature = "decimal")]
    pub respect_loss: rust_decimal::Decimal,

    #[cfg(not(feature = "decimal"))]
    pub respect: f32,
    #[cfg(not(feature = "decimal"))]
    pub respect_loss: f32,

    pub modifiers: RespectModifiers,
}