use serde::{Deserialize, Serialize};
use validator::Validate;
use crate::model::chat_base_response::ContentFilterInfo;
#[derive(Clone, Serialize, Deserialize, Validate)]
pub struct ImageResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Vec<ImageDataItem>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_filter: Option<Vec<ContentFilterInfo>>,
}
impl std::fmt::Debug for ImageResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string_pretty(self) {
Ok(s) => f.write_str(&s),
Err(_) => f.debug_struct("ImageResponse").finish(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct ImageDataItem {
#[serde(skip_serializing_if = "Option::is_none")]
#[validate(url)]
pub url: Option<String>,
}
impl ImageResponse {
pub fn created(&self) -> Option<u64> {
self.created
}
pub fn data(&self) -> Option<&[ImageDataItem]> {
self.data.as_deref()
}
pub fn content_filter(&self) -> Option<&[ContentFilterInfo]> {
self.content_filter.as_deref()
}
}
impl ImageDataItem {
pub fn url(&self) -> Option<&str> {
self.url.as_deref()
}
}