1use crate::prelude::*;
2
3pub struct StructuresGroup<'a> {
5 pub(crate) esi: &'a Esi,
6}
7
8#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
10pub struct MercenaryDenSummary {
11 pub id: i64,
13 pub planet_id: i64,
15}
16
17#[derive(Debug, Deserialize)]
18struct MercenaryDens {
19 mercenary_dens: Vec<MercenaryDenSummary>,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
24pub enum EvolutionLevel {
25 Unspecified,
27 Level0,
29 Level1,
31 Level2,
33 Level3,
35 Level4,
37 #[serde(other)]
39 Unrecognized,
40}
41
42#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
44pub struct EvolutionTrack {
45 pub amount: i64,
47 pub level: EvolutionLevel,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
53pub struct MercenaryDenEvolution {
54 pub anarchy: EvolutionTrack,
56 pub development: EvolutionTrack,
58}
59
60#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
62pub struct Infomorphs {
63 pub amount: i64,
65}
66
67#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
69pub struct EndTimer {
70 pub end: String,
72}
73
74#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
76pub struct DenSkyhook {
77 pub corporation_id: i64,
79 pub id: i64,
81 pub planet_id: i64,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
87pub enum MercenaryDenState {
88 Unspecified,
90 Running,
92 Paused,
94 Disabled,
96 #[serde(other)]
98 Unrecognized,
99}
100
101#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
103pub struct MercenaryDen {
104 pub evolution: MercenaryDenEvolution,
106 pub id: i64,
108 pub infomorphs: Infomorphs,
110 pub reinforcement_timer: Option<EndTimer>,
112 pub skyhook: DenSkyhook,
114 pub state: MercenaryDenState,
116 pub type_id: i64,
118}
119
120#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
122pub struct SkyhookSummary {
123 pub id: i64,
125 pub planet_id: i64,
127}
128
129#[derive(Debug, Deserialize)]
130struct Skyhooks {
131 skyhooks: Vec<SkyhookSummary>,
132}
133
134#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
136pub enum SkyhookState {
137 Unspecified,
139 ShieldVulnerable,
141 ArmorReinforced,
143 ArmorVulnerable,
145 HullReinforced,
147 HullVulnerable,
149 #[serde(other)]
151 Unrecognized,
152}
153
154#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
156pub struct SkyhookReagent {
157 pub last_cycle: String,
159 pub secured_stock: i64,
161 pub type_id: i64,
163 pub unsecured_stock: i64,
165}
166
167#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
169pub struct TimeWindow {
170 pub start: String,
172 pub end: String,
174}
175
176#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
178pub struct Skyhook {
179 pub effective_workforce: Option<i64>,
181 pub id: i64,
183 pub is_active: bool,
185 pub planet_id: i64,
187 #[serde(default)]
189 pub reagents: Vec<SkyhookReagent>,
190 pub reinforcement_timer: Option<EndTimer>,
192 pub state: SkyhookState,
194 pub theft_vulnerability: Option<TimeWindow>,
196}
197
198#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
200pub struct SovereigntyHubSummary {
201 pub id: i64,
203 pub solar_system_id: i64,
205}
206
207#[derive(Debug, Deserialize)]
208struct SovereigntyHubs {
209 sovereignty_hubs: Vec<SovereigntyHubSummary>,
210}
211
212#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
214pub struct HubReagent {
215 pub amount: i64,
217 pub burning_per_hour: i64,
219 pub type_id: i64,
221}
222
223#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
225pub struct ReagentBay {
226 pub last_updated: String,
228 pub reagents: Vec<HubReagent>,
230}
231
232#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
234pub struct ResourceUsage {
235 pub allocated: i64,
237 pub available: i64,
239}
240
241#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
243pub struct HubResources {
244 pub power: ResourceUsage,
246 pub workforce: ResourceUsage,
248}
249
250#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
252pub enum UpgradePowerState {
253 Unspecified,
255 Online,
257 Offline,
259 Low,
261 Pending,
263 #[serde(other)]
265 Unrecognized,
266}
267
268#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
270pub struct HubUpgrade {
271 pub power_state: UpgradePowerState,
273 pub type_id: i64,
275}
276
277#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
279pub struct WorkforceFlow {
280 pub amount: Option<i64>,
282 pub solar_system_id: Option<i64>,
284}
285
286#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
290pub struct WorkforceTransportMode {
291 pub export: Option<WorkforceFlow>,
293 pub import: Option<WorkforceImport>,
295 pub transit: Option<bool>,
297}
298
299#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
301pub struct WorkforceImport {
302 pub sources: Vec<WorkforceFlow>,
304}
305
306#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
308pub struct WorkforceTransport {
309 pub configuration: WorkforceTransportMode,
311 pub state: WorkforceTransportMode,
313}
314
315#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
317pub struct CorporationSovereigntyHub {
318 pub fuel_access_list_id: Option<i64>,
320 pub id: i64,
322 pub reagent_bay: ReagentBay,
324 pub resources: HubResources,
326 pub solar_system_id: i64,
328 pub upgrades: Vec<HubUpgrade>,
330 pub vulnerability_window: Option<TimeWindow>,
332 pub workforce_transport: WorkforceTransport,
334}
335
336impl StructuresGroup<'_> {
337 pub async fn get_character_mercenary_dens(
339 &self,
340 character_id: i64,
341 ) -> EsiResult<Vec<MercenaryDenSummary>> {
342 let path = self
343 .esi
344 .get_endpoint_for_op_id("GetCharactersStructuresMercenaryDensListing")?
345 .replace("{character_id}", &character_id.to_string());
346 let wrapper: MercenaryDens = self
347 .esi
348 .query("GET", RequestType::Authenticated, &path, None, None)
349 .await?;
350 Ok(wrapper.mercenary_dens)
351 }
352
353 api_get!(
354 get_character_mercenary_den,
356 "GetCharactersStructuresMercenaryDensDetail",
357 RequestType::Authenticated,
358 MercenaryDen,
359 (character_id: i64) => "{character_id}",
360 (mercenary_den_id: i64) => "{mercenary_den_id}"
361 );
362
363 pub async fn get_corporation_skyhooks(
367 &self,
368 corporation_id: i64,
369 ) -> EsiResult<Vec<SkyhookSummary>> {
370 let path = self
371 .esi
372 .get_endpoint_for_op_id("GetCorporationsStructuresSkyhooksListing")?
373 .replace("{corporation_id}", &corporation_id.to_string());
374 let wrapper: Skyhooks = self
375 .esi
376 .query("GET", RequestType::Authenticated, &path, None, None)
377 .await?;
378 Ok(wrapper.skyhooks)
379 }
380
381 api_get!(
382 get_corporation_skyhook,
386 "GetCorporationsStructuresSkyhooksDetail",
387 RequestType::Authenticated,
388 Skyhook,
389 (corporation_id: i64) => "{corporation_id}",
390 (skyhook_id: i64) => "{skyhook_id}"
391 );
392
393 pub async fn get_corporation_sovereignty_hubs(
395 &self,
396 corporation_id: i64,
397 ) -> EsiResult<Vec<SovereigntyHubSummary>> {
398 let path = self
399 .esi
400 .get_endpoint_for_op_id("GetCorporationsStructuresSovereigntyHubsListing")?
401 .replace("{corporation_id}", &corporation_id.to_string());
402 let wrapper: SovereigntyHubs = self
403 .esi
404 .query("GET", RequestType::Authenticated, &path, None, None)
405 .await?;
406 Ok(wrapper.sovereignty_hubs)
407 }
408
409 api_get!(
410 get_corporation_sovereignty_hub,
414 "GetCorporationsStructuresSovereigntyHubsDetail",
415 RequestType::Authenticated,
416 CorporationSovereigntyHub,
417 (corporation_id: i64) => "{corporation_id}",
418 (sovereignty_hub_id: i64) => "{sovereignty_hub_id}"
419 );
420}
421
422#[cfg(test)]
423mod tests {
424 use super::*;
425
426 #[test]
427 fn test_parse_mercenary_den() {
428 let json = r#"{"evolution": {"anarchy": {"amount": 5, "level": "Level2"},
429 "development": {"amount": 1, "level": "Level9"}},
430 "id": 1040000000000, "infomorphs": {"amount": 10},
431 "skyhook": {"corporation_id": 98000001, "id": 2, "planet_id": 40000001},
432 "state": "Running", "type_id": 85230}"#;
433 let den: MercenaryDen = serde_json::from_str(json).unwrap();
434 assert_eq!(den.id, 1_040_000_000_000);
435 assert_eq!(den.evolution.anarchy.level, EvolutionLevel::Level2);
436 assert_eq!(
437 den.evolution.development.level,
438 EvolutionLevel::Unrecognized
439 );
440 assert!(den.reinforcement_timer.is_none());
441 }
442
443 #[test]
444 fn test_parse_skyhook() {
445 let json = r#"{"id": 1, "is_active": true, "planet_id": 2, "state": "ArmorReinforced",
446 "reagents": [{"last_cycle": "t", "secured_stock": 1, "type_id": 81143, "unsecured_stock": 2}],
447 "theft_vulnerability": {"start": "a", "end": "b"}}"#;
448 let hook: Skyhook = serde_json::from_str(json).unwrap();
449 assert_eq!(hook.state, SkyhookState::ArmorReinforced);
450 assert_eq!(hook.reagents.len(), 1);
451 assert!(hook.effective_workforce.is_none());
452 }
453
454 #[test]
455 fn test_parse_sovereignty_hub() {
456 let json = r#"{"id": 1040000000001, "solar_system_id": 30000142,
457 "reagent_bay": {"last_updated": "t", "reagents": [{"amount": 1, "burning_per_hour": 2, "type_id": 81144}]},
458 "resources": {"power": {"allocated": 1, "available": 2}, "workforce": {"allocated": 3, "available": 4}},
459 "upgrades": [{"power_state": "Low", "type_id": 81615}],
460 "workforce_transport": {
461 "configuration": {"import": {"sources": [{"solar_system_id": 30000143}]}},
462 "state": {"transit": true}}}"#;
463 let hub: CorporationSovereigntyHub = serde_json::from_str(json).unwrap();
464 assert_eq!(hub.upgrades[0].power_state, UpgradePowerState::Low);
465 let cfg = &hub.workforce_transport.configuration;
466 assert_eq!(
467 cfg.import.as_ref().unwrap().sources[0].solar_system_id,
468 Some(30000143)
469 );
470 assert_eq!(hub.workforce_transport.state.transit, Some(true));
471 }
472}