use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
#[non_exhaustive]
pub enum MediaSource {
Url {
url: String,
media_type: Option<String>,
},
Base64 {
media_type: String,
data: String,
},
FileId {
id: String,
media_type: Option<String>,
},
}
impl MediaSource {
#[must_use]
pub fn base64(media_type: impl Into<String>, data: impl Into<String>) -> Self {
Self::Base64 {
media_type: media_type.into(),
data: data.into(),
}
}
#[must_use]
pub fn url(url: impl Into<String>) -> Self {
Self::Url {
url: url.into(),
media_type: None,
}
}
#[must_use]
pub fn file_id(id: impl Into<String>) -> Self {
Self::FileId {
id: id.into(),
media_type: None,
}
}
#[must_use]
pub fn media_type(&self) -> Option<&str> {
match self {
Self::Url { media_type, .. } | Self::FileId { media_type, .. } => media_type.as_deref(),
Self::Base64 { media_type, .. } => Some(media_type),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
#[non_exhaustive]
pub enum CitationSource {
Url {
url: String,
title: Option<String>,
},
Document {
document_index: u32,
title: Option<String>,
},
}