use serde::{Deserialize, Serialize};
use crate::error::EventKitError;
use crate::ffi;
use crate::private::{json_cstring, parse_json_ptr, redacted, Redacted};
pub const EK_VIRTUAL_CONFERENCE_PROVIDER_IS_EXTENSION_ONLY: bool = true;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EKVirtualConferenceRoomTypeDescriptor {
pub title: String,
pub identifier: String,
}
impl EKVirtualConferenceRoomTypeDescriptor {
pub fn new(title: impl Into<String>, identifier: impl Into<String>) -> Self {
Self {
title: title.into(),
identifier: identifier.into(),
}
}
pub fn roundtrip(&self) -> Result<Self, EventKitError> {
let payload = json_cstring(self, "EKVirtualConferenceRoomTypeDescriptor")?;
let mut error = core::ptr::null_mut();
let json = unsafe {
ffi::virtual_conference_provider::ek_virtual_conference_room_type_roundtrip_json(
payload.as_ptr(),
&raw mut error,
)
};
if json.is_null() {
Err(unsafe {
EventKitError::from_error_ptr(
error,
"virtual conference room type roundtrip failed",
)
})
} else {
unsafe { parse_json_ptr(json, "EKVirtualConferenceRoomTypeDescriptor") }
}
}
}
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EKVirtualConferenceURLDescriptor {
pub title: Option<String>,
pub url: String,
}
impl core::fmt::Debug for EKVirtualConferenceURLDescriptor {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("EKVirtualConferenceURLDescriptor")
.field("title", &self.title)
.field("url", &Redacted)
.finish()
}
}
impl EKVirtualConferenceURLDescriptor {
pub fn new(url: impl Into<String>) -> Self {
Self {
title: None,
url: url.into(),
}
}
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
pub fn roundtrip(&self) -> Result<Self, EventKitError> {
let payload = json_cstring(self, "EKVirtualConferenceURLDescriptor")?;
let mut error = core::ptr::null_mut();
let json = unsafe {
ffi::virtual_conference_provider::ek_virtual_conference_url_roundtrip_json(
payload.as_ptr(),
&raw mut error,
)
};
if json.is_null() {
Err(unsafe {
EventKitError::from_error_ptr(error, "virtual conference URL roundtrip failed")
})
} else {
unsafe { parse_json_ptr(json, "EKVirtualConferenceURLDescriptor") }
}
}
}
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EKVirtualConferenceDescriptor {
pub title: Option<String>,
#[serde(default)]
pub url_descriptors: Vec<EKVirtualConferenceURLDescriptor>,
pub conference_details: Option<String>,
}
impl core::fmt::Debug for EKVirtualConferenceDescriptor {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("EKVirtualConferenceDescriptor")
.field("title", &self.title)
.field("url_descriptors", &self.url_descriptors)
.field(
"conference_details",
&redacted(self.conference_details.as_ref()),
)
.finish()
}
}
impl EKVirtualConferenceDescriptor {
pub fn new(url_descriptors: Vec<EKVirtualConferenceURLDescriptor>) -> Self {
Self {
title: None,
url_descriptors,
conference_details: None,
}
}
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
pub fn with_conference_details(mut self, conference_details: impl Into<String>) -> Self {
self.conference_details = Some(conference_details.into());
self
}
pub fn roundtrip(&self) -> Result<Self, EventKitError> {
let payload = json_cstring(self, "EKVirtualConferenceDescriptor")?;
let mut error = core::ptr::null_mut();
let json = unsafe {
ffi::virtual_conference_provider::ek_virtual_conference_descriptor_roundtrip_json(
payload.as_ptr(),
&raw mut error,
)
};
if json.is_null() {
Err(unsafe {
EventKitError::from_error_ptr(
error,
"virtual conference descriptor roundtrip failed",
)
})
} else {
unsafe { parse_json_ptr(json, "EKVirtualConferenceDescriptor") }
}
}
}