Skip to main content

esi_openapi/groups/
structures.rs

1use crate::prelude::*;
2
3/// Endpoints for Structures
4pub struct StructuresGroup<'a> {
5    pub(crate) esi: &'a Esi,
6}
7
8/// A mercenary den owned by a character.
9#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
10pub struct MercenaryDenSummary {
11    /// ID of the mercenary den.
12    pub id: i64,
13    /// Planet the mercenary den is on.
14    pub planet_id: i64,
15}
16
17#[derive(Debug, Deserialize)]
18struct MercenaryDens {
19    mercenary_dens: Vec<MercenaryDenSummary>,
20}
21
22/// The level of a mercenary den evolution track.
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
24pub enum EvolutionLevel {
25    /// Not specified.
26    Unspecified,
27    /// Level 0.
28    Level0,
29    /// Level 1.
30    Level1,
31    /// Level 2.
32    Level2,
33    /// Level 3.
34    Level3,
35    /// Level 4.
36    Level4,
37    /// A value this version of the crate does not know about.
38    #[serde(other)]
39    Unrecognized,
40}
41
42/// Progress on one evolution track of a mercenary den.
43#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
44pub struct EvolutionTrack {
45    /// Amount accumulated.
46    pub amount: i64,
47    /// Current level.
48    pub level: EvolutionLevel,
49}
50
51/// The evolution tracks of a mercenary den.
52#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
53pub struct MercenaryDenEvolution {
54    /// Anarchy track.
55    pub anarchy: EvolutionTrack,
56    /// Development track.
57    pub development: EvolutionTrack,
58}
59
60/// Infomorphs stored in a mercenary den.
61#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
62pub struct Infomorphs {
63    /// Amount stored.
64    pub amount: i64,
65}
66
67/// A timer that has an end date.
68#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
69pub struct EndTimer {
70    /// When the timer ends.
71    pub end: String,
72}
73
74/// The skyhook a mercenary den is linked to.
75#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
76pub struct DenSkyhook {
77    /// Corporation that owns the skyhook.
78    pub corporation_id: i64,
79    /// ID of the skyhook.
80    pub id: i64,
81    /// Planet the skyhook is on.
82    pub planet_id: i64,
83}
84
85/// The state of a mercenary den.
86#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
87pub enum MercenaryDenState {
88    /// Not specified.
89    Unspecified,
90    /// Running.
91    Running,
92    /// Paused.
93    Paused,
94    /// Disabled.
95    Disabled,
96    /// A value this version of the crate does not know about.
97    #[serde(other)]
98    Unrecognized,
99}
100
101/// The details of a mercenary den.
102#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
103pub struct MercenaryDen {
104    /// Evolution tracks.
105    pub evolution: MercenaryDenEvolution,
106    /// ID of the mercenary den.
107    pub id: i64,
108    /// Infomorphs stored.
109    pub infomorphs: Infomorphs,
110    /// Reinforcement timer, if reinforced.
111    pub reinforcement_timer: Option<EndTimer>,
112    /// Linked skyhook.
113    pub skyhook: DenSkyhook,
114    /// State of the mercenary den.
115    pub state: MercenaryDenState,
116    /// Type ID of the mercenary den.
117    pub type_id: i64,
118}
119
120/// A skyhook owned by a corporation.
121#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
122pub struct SkyhookSummary {
123    /// ID of the skyhook.
124    pub id: i64,
125    /// Planet the skyhook is on.
126    pub planet_id: i64,
127}
128
129#[derive(Debug, Deserialize)]
130struct Skyhooks {
131    skyhooks: Vec<SkyhookSummary>,
132}
133
134/// The state of a skyhook.
135#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
136pub enum SkyhookState {
137    /// Not specified.
138    Unspecified,
139    /// Shield vulnerable.
140    ShieldVulnerable,
141    /// Armor reinforced.
142    ArmorReinforced,
143    /// Armor vulnerable.
144    ArmorVulnerable,
145    /// Hull reinforced.
146    HullReinforced,
147    /// Hull vulnerable.
148    HullVulnerable,
149    /// A value this version of the crate does not know about.
150    #[serde(other)]
151    Unrecognized,
152}
153
154/// Reagent stock in a skyhook.
155#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
156pub struct SkyhookReagent {
157    /// Last time the reagent was cycled.
158    pub last_cycle: String,
159    /// Secured stock.
160    pub secured_stock: i64,
161    /// Type ID of the reagent.
162    pub type_id: i64,
163    /// Unsecured stock.
164    pub unsecured_stock: i64,
165}
166
167/// A time window.
168#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
169pub struct TimeWindow {
170    /// Start of the window.
171    pub start: String,
172    /// End of the window.
173    pub end: String,
174}
175
176/// The details of a skyhook.
177#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
178pub struct Skyhook {
179    /// Effective workforce.
180    pub effective_workforce: Option<i64>,
181    /// ID of the skyhook.
182    pub id: i64,
183    /// Whether the skyhook is active.
184    pub is_active: bool,
185    /// Planet the skyhook is on.
186    pub planet_id: i64,
187    /// Reagent stock.
188    #[serde(default)]
189    pub reagents: Vec<SkyhookReagent>,
190    /// Reinforcement timer, if reinforced.
191    pub reinforcement_timer: Option<EndTimer>,
192    /// State of the skyhook.
193    pub state: SkyhookState,
194    /// Window in which the contents can be stolen.
195    pub theft_vulnerability: Option<TimeWindow>,
196}
197
198/// A sovereignty hub owned by a corporation.
199#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
200pub struct SovereigntyHubSummary {
201    /// ID of the hub.
202    pub id: i64,
203    /// Solar system of the hub.
204    pub solar_system_id: i64,
205}
206
207#[derive(Debug, Deserialize)]
208struct SovereigntyHubs {
209    sovereignty_hubs: Vec<SovereigntyHubSummary>,
210}
211
212/// Reagent burned by a sovereignty hub.
213#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
214pub struct HubReagent {
215    /// Amount in the bay.
216    pub amount: i64,
217    /// Amount burned per hour.
218    pub burning_per_hour: i64,
219    /// Type ID of the reagent.
220    pub type_id: i64,
221}
222
223/// The reagent bay of a sovereignty hub.
224#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
225pub struct ReagentBay {
226    /// When the bay was last updated.
227    pub last_updated: String,
228    /// Reagents in the bay.
229    pub reagents: Vec<HubReagent>,
230}
231
232/// Allocated and available amount of a resource.
233#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
234pub struct ResourceUsage {
235    /// Amount allocated.
236    pub allocated: i64,
237    /// Amount available.
238    pub available: i64,
239}
240
241/// Power and workforce of a sovereignty hub.
242#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
243pub struct HubResources {
244    /// Power usage.
245    pub power: ResourceUsage,
246    /// Workforce usage.
247    pub workforce: ResourceUsage,
248}
249
250/// The power state of a hub upgrade.
251#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
252pub enum UpgradePowerState {
253    /// Not specified.
254    Unspecified,
255    /// Online.
256    Online,
257    /// Offline.
258    Offline,
259    /// Low power.
260    Low,
261    /// Pending.
262    Pending,
263    /// A value this version of the crate does not know about.
264    #[serde(other)]
265    Unrecognized,
266}
267
268/// An upgrade installed in a sovereignty hub.
269#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
270pub struct HubUpgrade {
271    /// Power state of the upgrade.
272    pub power_state: UpgradePowerState,
273    /// Type ID of the upgrade.
274    pub type_id: i64,
275}
276
277/// A solar system and an amount of workforce.
278#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
279pub struct WorkforceFlow {
280    /// Amount of workforce.
281    pub amount: Option<i64>,
282    /// Solar system the workforce goes to or comes from.
283    pub solar_system_id: Option<i64>,
284}
285
286/// The workforce transport of a sovereignty hub, as configured or as running.
287///
288/// Exactly one of the fields is set.
289#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
290pub struct WorkforceTransportMode {
291    /// Workforce is exported.
292    pub export: Option<WorkforceFlow>,
293    /// Workforce is imported from the listed systems.
294    pub import: Option<WorkforceImport>,
295    /// Workforce is in transit.
296    pub transit: Option<bool>,
297}
298
299/// Workforce import sources.
300#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
301pub struct WorkforceImport {
302    /// Systems workforce is imported from.
303    pub sources: Vec<WorkforceFlow>,
304}
305
306/// The workforce transport of a sovereignty hub.
307#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
308pub struct WorkforceTransport {
309    /// Configured mode.
310    pub configuration: WorkforceTransportMode,
311    /// Mode currently running.
312    pub state: WorkforceTransportMode,
313}
314
315/// The details of a sovereignty hub.
316#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
317pub struct CorporationSovereigntyHub {
318    /// Access list that controls fuel access.
319    pub fuel_access_list_id: Option<i64>,
320    /// ID of the hub.
321    pub id: i64,
322    /// Reagent bay.
323    pub reagent_bay: ReagentBay,
324    /// Power and workforce.
325    pub resources: HubResources,
326    /// Solar system of the hub.
327    pub solar_system_id: i64,
328    /// Installed upgrades.
329    pub upgrades: Vec<HubUpgrade>,
330    /// Vulnerability window.
331    pub vulnerability_window: Option<TimeWindow>,
332    /// Workforce transport.
333    pub workforce_transport: WorkforceTransport,
334}
335
336impl StructuresGroup<'_> {
337    /// List the mercenary dens of a character.
338    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 the details of a mercenary den of a character.
355        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    /// List the skyhooks of a corporation.
364    ///
365    /// Requires the Station Manager role.
366    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 the details of a skyhook of a corporation.
383        ///
384        /// Requires the Station Manager role.
385        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    /// List the sovereignty hubs of a corporation.
394    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 the details of a sovereignty hub of a corporation.
411        ///
412        /// Requires the Station Manager role.
413        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}