use crate::types::PartResponse;
use crate::{WattpadClient, WattpadError};
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PartReference {
pub id: Option<u64>,
pub create_date: Option<String>,
}
impl PartReference {
pub async fn fetch_full_part(
&self,
client: &WattpadClient,
) -> Result<PartResponse, WattpadError> {
if let Some(id) = self.id {
client.story.get_part_info(id, None).await
} else {
Err(WattpadError::MissingRequiredField {
field: "id".to_string(),
context: "Cannot fetch full part without an id.".to_string(),
})
}
}
}