1#![allow(unused)]
2
3use crate::prelude::*;
4
5pub struct CalendarGroup<'a> {
7 pub(crate) esi: &'a Esi,
8}
9
10#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
11pub enum EventResponse {
13 #[serde(rename = "declined")]
15 Declined,
16 #[serde(rename = "not_responded")]
18 NotResponded,
19 #[serde(rename = "accepted")]
21 Accepted,
22 #[serde(rename = "tentative")]
24 Tentative,
25 #[serde(other)]
27 Unrecognized,
28}
29
30#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
31pub enum EventReply {
34 #[serde(rename = "accepted")]
36 Accepted,
37 #[serde(rename = "declined")]
39 Declined,
40 #[serde(rename = "tentative")]
42 Tentative,
43}
44
45#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
46pub enum EventOwnerType {
48 #[serde(rename = "eve_server")]
50 EveServer,
51 #[serde(rename = "corporation")]
53 Corporation,
54 #[serde(rename = "faction")]
56 Faction,
57 #[serde(rename = "character")]
59 Character,
60 #[serde(rename = "alliance")]
62 Alliance,
63 #[serde(other)]
65 Unrecognized,
66}
67
68#[derive(Debug, Deserialize, Serialize, Clone)]
69pub struct CalendarEventSummary {
71 pub event_date: Option<String>,
73 pub event_id: Option<i64>,
75 pub event_response: Option<EventResponse>,
77 pub importance: Option<i64>,
79 pub title: Option<String>,
81}
82
83#[derive(Debug, Deserialize, Serialize, Clone)]
84pub struct CalendarEvent {
86 pub date: String,
88 pub duration: i64,
90 pub event_id: i64,
92 pub importance: i64,
94 pub owner_id: i64,
96 pub owner_name: String,
98 pub owner_type: EventOwnerType,
100 pub response: String,
102 pub text: String,
104 pub title: String,
106}
107
108#[derive(Debug, Deserialize, Serialize, Clone)]
109pub struct EventAttendee {
111 pub character_id: Option<i64>,
113 pub event_response: Option<EventResponse>,
115}
116
117#[derive(Debug, Serialize, Clone, Copy)]
118pub struct EventResponseRequest {
120 pub response: EventReply,
122}
123
124impl CalendarGroup<'_> {
125 api_get!(
126 get_character_events,
129 "GetCharactersCharacterIdCalendar",
130 RequestType::Authenticated,
131 Vec<CalendarEventSummary>,
132 (character_id: i64) => "{character_id}";
133 Optional(from_event: i64) => "from_event"
134 );
135
136 api_get!(
137 get_character_event,
139 "GetCharactersCharacterIdCalendarEventId",
140 RequestType::Authenticated,
141 CalendarEvent,
142 (character_id: i64) => "{character_id}",
143 (event_id: i64) => "{event_id}"
144 );
145
146 api_put!(
147 respond_to_character_event,
149 "PutCharactersCharacterIdCalendarEventId",
150 RequestType::Authenticated,
151 (),
152 (character_id: i64) => "{character_id}",
153 (event_id: i64) => "{event_id}",
154 response: &EventResponseRequest,
155 );
156
157 api_get!(
158 get_character_event_attendees,
160 "GetCharactersCharacterIdCalendarEventIdAttendees",
161 RequestType::Authenticated,
162 Vec<EventAttendee>,
163 (character_id: i64) => "{character_id}",
164 (event_id: i64) => "{event_id}"
165 );
166}
167
168#[cfg(test)]
169mod calendar_tests {
170 use super::*;
171
172 #[test]
173 fn test_parse_events() {
174 let json = r#"[{"event_date": "2026-10-01T00:00:00Z", "event_id": 3000000000,
175 "event_response": "not_responded", "importance": 1, "title": "t"},
176 {"event_id": 1, "event_response": "maybe"}]"#;
177 let ev: Vec<CalendarEventSummary> = serde_json::from_str(json).unwrap();
178 assert_eq!(ev[0].event_id, Some(3_000_000_000));
179 assert_eq!(ev[0].event_response, Some(EventResponse::NotResponded));
180 assert_eq!(ev[1].event_response, Some(EventResponse::Unrecognized));
181 }
182
183 #[test]
184 fn test_parse_event_and_serialize_reply() {
185 let json = r#"{"date": "d", "duration": 60, "event_id": 1, "importance": 0, "owner_id": 5,
186 "owner_name": "n", "owner_type": "eve_server", "response": "accepted", "text": "x", "title": "t"}"#;
187 let e: CalendarEvent = serde_json::from_str(json).unwrap();
188 assert_eq!(e.owner_type, EventOwnerType::EveServer);
189 let body = EventResponseRequest {
190 response: EventReply::Tentative,
191 };
192 assert_eq!(
193 serde_json::to_string(&body).unwrap(),
194 r#"{"response":"tentative"}"#
195 );
196 }
197}