1use crate::prelude::*;
2
3pub struct SovereigntyGroup<'a> {
5 pub(crate) esi: &'a Esi,
6}
7
8#[derive(Debug, Clone, PartialEq, Deserialize)]
10#[allow(missing_docs)]
11pub struct CampaignParticipant {
12 pub alliance_id: i64,
13 pub score: f64,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
18#[serde(rename_all = "snake_case")]
19pub enum CampaignEventType {
20 TcuDefense,
22 IhubDefense,
24 StationDefense,
26 StationFreeport,
28 #[serde(other)]
30 Unrecognized,
31}
32
33#[derive(Debug, Clone, PartialEq, Deserialize)]
35#[allow(missing_docs)]
36pub struct SovereigntyCampaign {
37 pub attackers_score: Option<f64>,
38 pub campaign_id: i64,
39 pub constellation_id: i64,
40 pub defender_id: Option<i64>,
41 pub defender_score: Option<f64>,
42 pub event_type: CampaignEventType,
43 pub participants: Option<Vec<CampaignParticipant>>,
44 pub solar_system_id: i64,
45 pub start_time: String,
46 pub structure_id: i64,
47}
48
49#[derive(Debug, Clone, PartialEq, Deserialize)]
51#[allow(missing_docs)]
52pub struct VulnerabilityWindow {
53 pub end: String,
54 pub start: String,
55}
56
57#[derive(Debug, Clone, PartialEq, Deserialize)]
59#[allow(missing_docs)]
60pub struct SovereigntyHub {
61 pub id: i64,
62 pub vulnerability_window: Option<VulnerabilityWindow>,
63}
64
65#[derive(Debug, Clone, PartialEq, Deserialize)]
67#[allow(missing_docs)]
68pub struct SystemDevelopment {
69 pub activity_defense_multiplier: f64,
70 pub industrial_level: i64,
71 pub military_level: i64,
72 pub strategic_level: i64,
73}
74
75#[derive(Debug, Clone, PartialEq, Deserialize)]
77#[allow(missing_docs)]
78pub struct AllianceClaim {
79 pub alliance_id: i64,
80 pub claimed_since: String,
81 pub corporation_id: i64,
82 pub development: SystemDevelopment,
83 pub is_capital_system: bool,
84 pub sovereignty_hub: SovereigntyHub,
85}
86
87#[derive(Debug, Clone, PartialEq, Deserialize)]
89#[allow(missing_docs)]
90pub struct FactionClaim {
91 pub faction_id: i64,
92}
93
94#[derive(Debug, Clone, PartialEq, Deserialize)]
96#[serde(untagged)]
97#[allow(missing_docs)]
98pub enum SovereigntyClaim {
99 Faction { faction: FactionClaim },
100 Alliance { alliance: AllianceClaim },
101 Unclaimed { unclaimed: bool },
102}
103
104#[derive(Debug, Clone, PartialEq, Deserialize)]
106#[allow(missing_docs)]
107pub struct SovereigntySystem {
108 pub claim: SovereigntyClaim,
109 pub solar_system_id: i64,
110}
111
112#[derive(Debug, Deserialize)]
113struct SovereigntySystems {
114 solar_systems: Vec<SovereigntySystem>,
115}
116
117impl SovereigntyGroup<'_> {
118 api_get!(
119 get_campaigns,
121 "GetSovereigntyCampaigns",
122 RequestType::Public,
123 Vec<SovereigntyCampaign>,
124 );
125
126 pub async fn get_systems(&self) -> EsiResult<Vec<SovereigntySystem>> {
128 let path = self.esi.get_endpoint_for_op_id("GetSovereigntySystems")?;
129 let wrapper: SovereigntySystems = self
130 .esi
131 .query("GET", RequestType::Public, &path, None, None)
132 .await?;
133 Ok(wrapper.solar_systems)
134 }
135}
136
137#[cfg(test)]
138mod tests {
139 use super::{SovereigntyClaim, SovereigntySystem};
140
141 #[test]
142 fn test_parse_each_claim_kind() {
143 let faction: SovereigntySystem = serde_json::from_str(
144 r#"{"solar_system_id":1,"claim":{"faction":{"faction_id":500001}}}"#,
145 )
146 .unwrap();
147 assert!(matches!(faction.claim, SovereigntyClaim::Faction { .. }));
148
149 let none: SovereigntySystem =
150 serde_json::from_str(r#"{"solar_system_id":2,"claim":{"unclaimed":true}}"#).unwrap();
151 assert!(matches!(
152 none.claim,
153 SovereigntyClaim::Unclaimed { unclaimed: true }
154 ));
155
156 let alliance: SovereigntySystem = serde_json::from_str(
157 r#"{"solar_system_id":3,"claim":{"alliance":{
158 "alliance_id":1,"corporation_id":2,"claimed_since":"2026-01-01T00:00:00Z",
159 "is_capital_system":false,
160 "development":{"activity_defense_multiplier":1.0,"industrial_level":1,"military_level":2,"strategic_level":3},
161 "sovereignty_hub":{"id":9}}}}"#,
162 )
163 .unwrap();
164 assert!(matches!(alliance.claim, SovereigntyClaim::Alliance { .. }));
165 }
166}