#![allow(unused)]
use crate::prelude::*;
pub struct CalendarGroup<'a> {
pub(crate) esi: &'a Esi,
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
pub enum EventResponse {
#[serde(rename = "declined")]
Declined,
#[serde(rename = "not_responded")]
NotResponded,
#[serde(rename = "accepted")]
Accepted,
#[serde(rename = "tentative")]
Tentative,
#[serde(other)]
Unrecognized,
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
pub enum EventReply {
#[serde(rename = "accepted")]
Accepted,
#[serde(rename = "declined")]
Declined,
#[serde(rename = "tentative")]
Tentative,
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
pub enum EventOwnerType {
#[serde(rename = "eve_server")]
EveServer,
#[serde(rename = "corporation")]
Corporation,
#[serde(rename = "faction")]
Faction,
#[serde(rename = "character")]
Character,
#[serde(rename = "alliance")]
Alliance,
#[serde(other)]
Unrecognized,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CalendarEventSummary {
pub event_date: Option<String>,
pub event_id: Option<i64>,
pub event_response: Option<EventResponse>,
pub importance: Option<i64>,
pub title: Option<String>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CalendarEvent {
pub date: String,
pub duration: i64,
pub event_id: i64,
pub importance: i64,
pub owner_id: i64,
pub owner_name: String,
pub owner_type: EventOwnerType,
pub response: String,
pub text: String,
pub title: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct EventAttendee {
pub character_id: Option<i64>,
pub event_response: Option<EventResponse>,
}
#[derive(Debug, Serialize, Clone, Copy)]
pub struct EventResponseRequest {
pub response: EventReply,
}
impl CalendarGroup<'_> {
api_get!(
get_character_events,
"GetCharactersCharacterIdCalendar",
RequestType::Authenticated,
Vec<CalendarEventSummary>,
(character_id: i64) => "{character_id}";
Optional(from_event: i64) => "from_event"
);
api_get!(
get_character_event,
"GetCharactersCharacterIdCalendarEventId",
RequestType::Authenticated,
CalendarEvent,
(character_id: i64) => "{character_id}",
(event_id: i64) => "{event_id}"
);
api_put!(
respond_to_character_event,
"PutCharactersCharacterIdCalendarEventId",
RequestType::Authenticated,
(),
(character_id: i64) => "{character_id}",
(event_id: i64) => "{event_id}",
response: &EventResponseRequest,
);
api_get!(
get_character_event_attendees,
"GetCharactersCharacterIdCalendarEventIdAttendees",
RequestType::Authenticated,
Vec<EventAttendee>,
(character_id: i64) => "{character_id}",
(event_id: i64) => "{event_id}"
);
}
#[cfg(test)]
mod calendar_tests {
use super::*;
#[test]
fn test_parse_events() {
let json = r#"[{"event_date": "2026-10-01T00:00:00Z", "event_id": 3000000000,
"event_response": "not_responded", "importance": 1, "title": "t"},
{"event_id": 1, "event_response": "maybe"}]"#;
let ev: Vec<CalendarEventSummary> = serde_json::from_str(json).unwrap();
assert_eq!(ev[0].event_id, Some(3_000_000_000));
assert_eq!(ev[0].event_response, Some(EventResponse::NotResponded));
assert_eq!(ev[1].event_response, Some(EventResponse::Unrecognized));
}
#[test]
fn test_parse_event_and_serialize_reply() {
let json = r#"{"date": "d", "duration": 60, "event_id": 1, "importance": 0, "owner_id": 5,
"owner_name": "n", "owner_type": "eve_server", "response": "accepted", "text": "x", "title": "t"}"#;
let e: CalendarEvent = serde_json::from_str(json).unwrap();
assert_eq!(e.owner_type, EventOwnerType::EveServer);
let body = EventResponseRequest {
response: EventReply::Tentative,
};
assert_eq!(
serde_json::to_string(&body).unwrap(),
r#"{"response":"tentative"}"#
);
}
}