use serde::{Deserialize, Serialize};
use super::request::FormatType;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ParserStatus {
Processing,
Succeeded,
Failed,
}
impl std::fmt::Display for ParserStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ParserStatus::Processing => write!(f, "processing"),
ParserStatus::Succeeded => write!(f, "succeeded"),
ParserStatus::Failed => write!(f, "failed"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileParserResultResponse {
pub status: ParserStatus,
pub message: String,
pub task_id: String,
pub content: Option<String>,
#[serde(rename = "parsing_result_url")]
pub parsing_result_url: Option<String>,
}
impl FileParserResultResponse {
pub fn is_success(&self) -> bool {
self.status == ParserStatus::Succeeded
}
pub fn is_processing(&self) -> bool {
self.status == ParserStatus::Processing
}
pub fn is_failed(&self) -> bool {
self.status == ParserStatus::Failed
}
pub fn task_id(&self) -> &str {
&self.task_id
}
pub fn content(&self) -> Option<&str> {
self.content.as_deref()
}
pub fn download_url(&self) -> Option<&str> {
self.parsing_result_url.as_deref()
}
pub fn get_result(&self, format_type: &FormatType) -> Option<&str> {
match format_type {
FormatType::Text => self.content(),
FormatType::DownloadLink => self.download_url(),
}
}
}