use super::CatalogEndpoint;
use openlark_core::api::{ApiRequest, HttpMethod};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum BaikeApiV1 {
DraftCreate,
DraftUpdate(String),
EntityCreate,
EntityUpdate(String),
EntityGet(String),
EntityList,
EntityMatch,
EntitySearch,
EntityHighlight,
EntityExtract,
ClassificationList,
FileUpload,
FileDownload(String),
}
impl BaikeApiV1 {
pub fn to_url(&self) -> String {
match self {
BaikeApiV1::DraftCreate => "/open-apis/baike/v1/drafts".to_string(),
BaikeApiV1::DraftUpdate(draft_id) => {
format!("/open-apis/baike/v1/drafts/{draft_id}")
}
BaikeApiV1::EntityCreate => "/open-apis/baike/v1/entities".to_string(),
BaikeApiV1::EntityUpdate(entity_id) => {
format!("/open-apis/baike/v1/entities/{entity_id}")
}
BaikeApiV1::EntityGet(entity_id) => {
format!("/open-apis/baike/v1/entities/{entity_id}")
}
BaikeApiV1::EntityList => "/open-apis/baike/v1/entities".to_string(),
BaikeApiV1::EntityMatch => "/open-apis/baike/v1/entities/match".to_string(),
BaikeApiV1::EntitySearch => "/open-apis/baike/v1/entities/search".to_string(),
BaikeApiV1::EntityHighlight => "/open-apis/baike/v1/entities/highlight".to_string(),
BaikeApiV1::EntityExtract => "/open-apis/baike/v1/entities/extract".to_string(),
BaikeApiV1::ClassificationList => "/open-apis/baike/v1/classifications".to_string(),
BaikeApiV1::FileUpload => "/open-apis/baike/v1/files/upload".to_string(),
BaikeApiV1::FileDownload(file_token) => {
format!("/open-apis/baike/v1/files/{file_token}/download")
}
}
}
pub fn to_request<R>(&self) -> ApiRequest<R> {
<Self as CatalogEndpoint>::to_request(self)
}
}
impl CatalogEndpoint for BaikeApiV1 {
fn to_url(&self) -> String {
BaikeApiV1::to_url(self)
}
fn method(&self) -> HttpMethod {
match self {
Self::EntityGet(_)
| Self::EntityList
| Self::ClassificationList
| Self::FileDownload(_) => HttpMethod::Get,
Self::DraftUpdate(_) | Self::EntityUpdate(_) => HttpMethod::Put,
Self::DraftCreate
| Self::EntityCreate
| Self::EntityMatch
| Self::EntitySearch
| Self::EntityHighlight
| Self::EntityExtract
| Self::FileUpload => HttpMethod::Post,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::common::api_endpoints::test_support::catalog_semantics_snapshot;
#[test]
fn baike_catalog_semantics_snapshot() {
insta::assert_snapshot!(catalog_semantics_snapshot::<BaikeApiV1>());
}
}