use super::CatalogEndpoint;
use openlark_core::api::{ApiRequest, HttpMethod};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum LingoApiV1 {
DraftCreate,
DraftUpdate(String),
EntityCreate,
EntityUpdate(String), EntityDelete(String), EntityGet(String), EntityList,
EntityMatch,
EntitySearch,
EntityHighlight,
EntityBatchGet,
EntityBatchUpdate,
EntitySearchRecommend,
EntityExtract,
EntityHistoryGet(String), EntityHistoryList,
ClassificationList,
RepoList,
FileUpload,
FileDownload(String),
GenerateSummary,
ExtractKeywords,
TranslateText,
}
impl LingoApiV1 {
pub fn to_url(&self) -> String {
match self {
LingoApiV1::DraftCreate => "/open-apis/lingo/v1/drafts".to_string(),
LingoApiV1::DraftUpdate(draft_id) => {
format!("/open-apis/lingo/v1/drafts/{draft_id}")
}
LingoApiV1::EntityCreate => "/open-apis/lingo/v1/entities".to_string(),
LingoApiV1::EntityUpdate(entity_id) => {
format!("/open-apis/lingo/v1/entities/{entity_id}")
}
LingoApiV1::EntityDelete(entity_id) => {
format!("/open-apis/lingo/v1/entities/{entity_id}")
}
LingoApiV1::EntityGet(entity_id) => {
format!("/open-apis/lingo/v1/entities/{entity_id}")
}
LingoApiV1::EntityList => "/open-apis/lingo/v1/entities".to_string(),
LingoApiV1::EntityMatch => "/open-apis/baike/v1/entities/match".to_string(),
LingoApiV1::EntitySearch => "/open-apis/lingo/v1/entities/search".to_string(),
LingoApiV1::EntityHighlight => "/open-apis/lingo/v1/entities/highlight".to_string(),
LingoApiV1::EntityBatchGet => "/open-apis/lingo/v1/entities:batchGet".to_string(),
LingoApiV1::EntityBatchUpdate => "/open-apis/lingo/v1/entities:batchUpdate".to_string(),
LingoApiV1::EntitySearchRecommend => {
"/open-apis/lingo/v1/entities:searchRecommend".to_string()
}
LingoApiV1::EntityExtract => "/open-apis/baike/v1/entities/extract".to_string(),
LingoApiV1::EntityHistoryGet(entity_id) => {
format!("/open-apis/lingo/v1/entities/{entity_id}/history")
}
LingoApiV1::EntityHistoryList => "/open-apis/lingo/v1/entityHistory".to_string(),
LingoApiV1::ClassificationList => "/open-apis/lingo/v1/classifications".to_string(),
LingoApiV1::RepoList => "/open-apis/lingo/v1/repos".to_string(),
LingoApiV1::FileUpload => "/open-apis/lingo/v1/files/upload".to_string(),
LingoApiV1::FileDownload(file_token) => {
format!("/open-apis/lingo/v1/files/{file_token}/download")
}
LingoApiV1::GenerateSummary => "/open-apis/lingo/v1/text:generateSummary".to_string(),
LingoApiV1::ExtractKeywords => "/open-apis/lingo/v1/text:extractKeywords".to_string(),
LingoApiV1::TranslateText => "/open-apis/lingo/v1/text:translate".to_string(),
}
}
pub fn to_request<R>(&self) -> ApiRequest<R> {
<Self as CatalogEndpoint>::to_request(self)
}
}
impl CatalogEndpoint for LingoApiV1 {
fn to_url(&self) -> String {
LingoApiV1::to_url(self)
}
fn method(&self) -> HttpMethod {
match self {
Self::EntityGet(_)
| Self::EntityList
| Self::EntityHistoryGet(_)
| Self::EntityHistoryList
| Self::ClassificationList
| Self::RepoList
| Self::FileDownload(_) => HttpMethod::Get,
Self::DraftUpdate(_) | Self::EntityUpdate(_) => HttpMethod::Put,
Self::EntityDelete(_) => HttpMethod::Delete,
Self::DraftCreate
| Self::EntityCreate
| Self::EntityMatch
| Self::EntitySearch
| Self::EntityHighlight
| Self::EntityBatchGet
| Self::EntityBatchUpdate
| Self::EntitySearchRecommend
| Self::FileUpload
| Self::GenerateSummary
| Self::ExtractKeywords
| Self::TranslateText => HttpMethod::Post,
Self::EntityExtract => HttpMethod::Post,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::common::api_endpoints::test_support::catalog_semantics_snapshot;
#[test]
fn lingo_catalog_semantics_snapshot() {
insta::assert_snapshot!(catalog_semantics_snapshot::<LingoApiV1>());
}
}