1#![allow(unused)]
2
3use crate::prelude::*;
4
5pub struct FittingsGroup<'a> {
7 pub(crate) esi: &'a Esi,
8}
9
10#[allow(missing_docs)]
11#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
12pub enum FittingFlag {
15 Cargo,
16 DroneBay,
17 FighterBay,
18 HiSlot0,
19 HiSlot1,
20 HiSlot2,
21 HiSlot3,
22 HiSlot4,
23 HiSlot5,
24 HiSlot6,
25 HiSlot7,
26 Invalid,
27 LoSlot0,
28 LoSlot1,
29 LoSlot2,
30 LoSlot3,
31 LoSlot4,
32 LoSlot5,
33 LoSlot6,
34 LoSlot7,
35 MedSlot0,
36 MedSlot1,
37 MedSlot2,
38 MedSlot3,
39 MedSlot4,
40 MedSlot5,
41 MedSlot6,
42 MedSlot7,
43 RigSlot0,
44 RigSlot1,
45 RigSlot2,
46 ServiceSlot0,
47 ServiceSlot1,
48 ServiceSlot2,
49 ServiceSlot3,
50 ServiceSlot4,
51 ServiceSlot5,
52 ServiceSlot6,
53 ServiceSlot7,
54 SubSystemSlot0,
55 SubSystemSlot1,
56 SubSystemSlot2,
57 SubSystemSlot3,
58 #[serde(other)]
60 Unrecognized,
61}
62
63#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
64pub struct FittingItem {
66 pub flag: FittingFlag,
68 pub quantity: i64,
70 pub type_id: i64,
72}
73
74#[derive(Debug, Deserialize, Serialize, Clone)]
75pub struct Fitting {
77 pub description: String,
79 pub fitting_id: i64,
81 pub items: Vec<FittingItem>,
83 pub name: String,
85 pub ship_type_id: i64,
87}
88
89#[derive(Debug, Serialize, Clone)]
90pub struct NewFitting {
92 pub description: String,
94 pub items: Vec<FittingItem>,
96 pub name: String,
98 pub ship_type_id: i64,
100}
101
102impl FittingsGroup<'_> {
103 api_get!(
104 get_character_fittings,
106 "GetCharactersCharacterIdFittings",
107 RequestType::Authenticated,
108 Vec<Fitting>,
109 (character_id: i64) => "{character_id}"
110 );
111
112 api_post!(
113 create_character_fitting,
115 "PostCharactersCharacterIdFittings",
116 RequestType::Authenticated,
117 i64,
118 (character_id: i64) => "{character_id}",
119 fitting: &NewFitting,
120 );
121
122 api_delete!(
123 delete_character_fitting,
125 "DeleteCharactersCharacterIdFittingsFittingId",
126 RequestType::Authenticated,
127 (),
128 (character_id: i64) => "{character_id}",
129 (fitting_id: i64) => "{fitting_id}"
130 );
131}
132
133#[cfg(test)]
134mod fittings_tests {
135 use super::*;
136
137 #[test]
138 fn test_parse_fitting() {
139 let json = r#"[{"description": "d", "fitting_id": 3000000000, "name": "n", "ship_type_id": 587,
140 "items": [{"flag": "HiSlot0", "quantity": 1, "type_id": 3001},
141 {"flag": "NewSlot", "quantity": 2, "type_id": 1}]}]"#;
142 let fits: Vec<Fitting> = serde_json::from_str(json).unwrap();
143 assert_eq!(fits[0].fitting_id, 3_000_000_000);
144 assert_eq!(fits[0].items[0].flag, FittingFlag::HiSlot0);
145 assert_eq!(fits[0].items[1].flag, FittingFlag::Unrecognized);
146 }
147
148 #[test]
149 fn test_serialize_new_fitting() {
150 let f = NewFitting {
151 description: "d".into(),
152 items: vec![FittingItem {
153 flag: FittingFlag::SubSystemSlot3,
154 quantity: 1,
155 type_id: 5,
156 }],
157 name: "n".into(),
158 ship_type_id: 1,
159 };
160 let v = serde_json::to_value(&f).unwrap();
161 assert_eq!(v["items"][0]["flag"], "SubSystemSlot3");
162 }
163}