use crate::prelude::*;
pub struct StructuresGroup<'a> {
pub(crate) esi: &'a Esi,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct MercenaryDenSummary {
pub id: i64,
pub planet_id: i64,
}
#[derive(Debug, Deserialize)]
struct MercenaryDens {
mercenary_dens: Vec<MercenaryDenSummary>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum EvolutionLevel {
Unspecified,
Level0,
Level1,
Level2,
Level3,
Level4,
#[serde(other)]
Unrecognized,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct EvolutionTrack {
pub amount: i64,
pub level: EvolutionLevel,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct MercenaryDenEvolution {
pub anarchy: EvolutionTrack,
pub development: EvolutionTrack,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Infomorphs {
pub amount: i64,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct EndTimer {
pub end: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DenSkyhook {
pub corporation_id: i64,
pub id: i64,
pub planet_id: i64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum MercenaryDenState {
Unspecified,
Running,
Paused,
Disabled,
#[serde(other)]
Unrecognized,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct MercenaryDen {
pub evolution: MercenaryDenEvolution,
pub id: i64,
pub infomorphs: Infomorphs,
pub reinforcement_timer: Option<EndTimer>,
pub skyhook: DenSkyhook,
pub state: MercenaryDenState,
pub type_id: i64,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct SkyhookSummary {
pub id: i64,
pub planet_id: i64,
}
#[derive(Debug, Deserialize)]
struct Skyhooks {
skyhooks: Vec<SkyhookSummary>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum SkyhookState {
Unspecified,
ShieldVulnerable,
ArmorReinforced,
ArmorVulnerable,
HullReinforced,
HullVulnerable,
#[serde(other)]
Unrecognized,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct SkyhookReagent {
pub last_cycle: String,
pub secured_stock: i64,
pub type_id: i64,
pub unsecured_stock: i64,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct TimeWindow {
pub start: String,
pub end: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Skyhook {
pub effective_workforce: Option<i64>,
pub id: i64,
pub is_active: bool,
pub planet_id: i64,
#[serde(default)]
pub reagents: Vec<SkyhookReagent>,
pub reinforcement_timer: Option<EndTimer>,
pub state: SkyhookState,
pub theft_vulnerability: Option<TimeWindow>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct SovereigntyHubSummary {
pub id: i64,
pub solar_system_id: i64,
}
#[derive(Debug, Deserialize)]
struct SovereigntyHubs {
sovereignty_hubs: Vec<SovereigntyHubSummary>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct HubReagent {
pub amount: i64,
pub burning_per_hour: i64,
pub type_id: i64,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ReagentBay {
pub last_updated: String,
pub reagents: Vec<HubReagent>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ResourceUsage {
pub allocated: i64,
pub available: i64,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct HubResources {
pub power: ResourceUsage,
pub workforce: ResourceUsage,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum UpgradePowerState {
Unspecified,
Online,
Offline,
Low,
Pending,
#[serde(other)]
Unrecognized,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct HubUpgrade {
pub power_state: UpgradePowerState,
pub type_id: i64,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct WorkforceFlow {
pub amount: Option<i64>,
pub solar_system_id: Option<i64>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct WorkforceTransportMode {
pub export: Option<WorkforceFlow>,
pub import: Option<WorkforceImport>,
pub transit: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct WorkforceImport {
pub sources: Vec<WorkforceFlow>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct WorkforceTransport {
pub configuration: WorkforceTransportMode,
pub state: WorkforceTransportMode,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct CorporationSovereigntyHub {
pub fuel_access_list_id: Option<i64>,
pub id: i64,
pub reagent_bay: ReagentBay,
pub resources: HubResources,
pub solar_system_id: i64,
pub upgrades: Vec<HubUpgrade>,
pub vulnerability_window: Option<TimeWindow>,
pub workforce_transport: WorkforceTransport,
}
impl StructuresGroup<'_> {
pub async fn get_character_mercenary_dens(
&self,
character_id: i64,
) -> EsiResult<Vec<MercenaryDenSummary>> {
let path = self
.esi
.get_endpoint_for_op_id("GetCharactersStructuresMercenaryDensListing")?
.replace("{character_id}", &character_id.to_string());
let wrapper: MercenaryDens = self
.esi
.query("GET", RequestType::Authenticated, &path, None, None)
.await?;
Ok(wrapper.mercenary_dens)
}
api_get!(
get_character_mercenary_den,
"GetCharactersStructuresMercenaryDensDetail",
RequestType::Authenticated,
MercenaryDen,
(character_id: i64) => "{character_id}",
(mercenary_den_id: i64) => "{mercenary_den_id}"
);
pub async fn get_corporation_skyhooks(
&self,
corporation_id: i64,
) -> EsiResult<Vec<SkyhookSummary>> {
let path = self
.esi
.get_endpoint_for_op_id("GetCorporationsStructuresSkyhooksListing")?
.replace("{corporation_id}", &corporation_id.to_string());
let wrapper: Skyhooks = self
.esi
.query("GET", RequestType::Authenticated, &path, None, None)
.await?;
Ok(wrapper.skyhooks)
}
api_get!(
get_corporation_skyhook,
"GetCorporationsStructuresSkyhooksDetail",
RequestType::Authenticated,
Skyhook,
(corporation_id: i64) => "{corporation_id}",
(skyhook_id: i64) => "{skyhook_id}"
);
pub async fn get_corporation_sovereignty_hubs(
&self,
corporation_id: i64,
) -> EsiResult<Vec<SovereigntyHubSummary>> {
let path = self
.esi
.get_endpoint_for_op_id("GetCorporationsStructuresSovereigntyHubsListing")?
.replace("{corporation_id}", &corporation_id.to_string());
let wrapper: SovereigntyHubs = self
.esi
.query("GET", RequestType::Authenticated, &path, None, None)
.await?;
Ok(wrapper.sovereignty_hubs)
}
api_get!(
get_corporation_sovereignty_hub,
"GetCorporationsStructuresSovereigntyHubsDetail",
RequestType::Authenticated,
CorporationSovereigntyHub,
(corporation_id: i64) => "{corporation_id}",
(sovereignty_hub_id: i64) => "{sovereignty_hub_id}"
);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_mercenary_den() {
let json = r#"{"evolution": {"anarchy": {"amount": 5, "level": "Level2"},
"development": {"amount": 1, "level": "Level9"}},
"id": 1040000000000, "infomorphs": {"amount": 10},
"skyhook": {"corporation_id": 98000001, "id": 2, "planet_id": 40000001},
"state": "Running", "type_id": 85230}"#;
let den: MercenaryDen = serde_json::from_str(json).unwrap();
assert_eq!(den.id, 1_040_000_000_000);
assert_eq!(den.evolution.anarchy.level, EvolutionLevel::Level2);
assert_eq!(
den.evolution.development.level,
EvolutionLevel::Unrecognized
);
assert!(den.reinforcement_timer.is_none());
}
#[test]
fn test_parse_skyhook() {
let json = r#"{"id": 1, "is_active": true, "planet_id": 2, "state": "ArmorReinforced",
"reagents": [{"last_cycle": "t", "secured_stock": 1, "type_id": 81143, "unsecured_stock": 2}],
"theft_vulnerability": {"start": "a", "end": "b"}}"#;
let hook: Skyhook = serde_json::from_str(json).unwrap();
assert_eq!(hook.state, SkyhookState::ArmorReinforced);
assert_eq!(hook.reagents.len(), 1);
assert!(hook.effective_workforce.is_none());
}
#[test]
fn test_parse_sovereignty_hub() {
let json = r#"{"id": 1040000000001, "solar_system_id": 30000142,
"reagent_bay": {"last_updated": "t", "reagents": [{"amount": 1, "burning_per_hour": 2, "type_id": 81144}]},
"resources": {"power": {"allocated": 1, "available": 2}, "workforce": {"allocated": 3, "available": 4}},
"upgrades": [{"power_state": "Low", "type_id": 81615}],
"workforce_transport": {
"configuration": {"import": {"sources": [{"solar_system_id": 30000143}]}},
"state": {"transit": true}}}"#;
let hub: CorporationSovereigntyHub = serde_json::from_str(json).unwrap();
assert_eq!(hub.upgrades[0].power_state, UpgradePowerState::Low);
let cfg = &hub.workforce_transport.configuration;
assert_eq!(
cfg.import.as_ref().unwrap().sources[0].solar_system_id,
Some(30000143)
);
assert_eq!(hub.workforce_transport.state.transit, Some(true));
}
}