use super::{
AIGatewayPlane, AIGatewayWorkspaceGetOptions, AIGatewayWorkspaceListOptions,
AIGatewayWorkspaceStatus, common, models::*,
};
use crate::{Client, Endpoint, RawRequest, RequestOptions, Result};
use http::Method;
#[derive(Clone, Debug)]
pub struct AIGatewayWorkspacesClient {
pub(super) client: Client,
pub(super) admin: Client,
pub(super) iam: Option<crate::shared::iam::IamScopesClient>,
}
impl AIGatewayWorkspacesClient {
pub fn new(client: Client, admin_endpoint: Endpoint) -> Result<Self> {
let client = common::oauth(client)?;
let admin = client.with_endpoint(admin_endpoint)?;
Ok(Self {
client,
admin,
iam: None,
})
}
pub fn with_iam_endpoint(mut self, endpoint: Endpoint) -> Result<Self> {
self.iam = Some(crate::shared::iam::IamScopesClient::new(
self.client.with_endpoint(endpoint)?,
)?);
Ok(self)
}
pub fn client(&self) -> &Client {
&self.client
}
fn plane(&self, plane: AIGatewayPlane) -> &Client {
match plane {
AIGatewayPlane::Data => &self.client,
AIGatewayPlane::Admin => &self.admin,
}
}
pub async fn list(
&self,
params: &AIGatewayWorkspaceListOptions,
options: Option<&RequestOptions>,
) -> Result<ListWorkspacesResponse> {
let query = params
.status
.map(|status| {
vec![(
"status".into(),
match status {
AIGatewayWorkspaceStatus::Active => "active",
AIGatewayWorkspaceStatus::Archived => "archived",
}
.into(),
)]
})
.unwrap_or_default();
self.plane(params.plane)
.send_contract(
RawRequest::read("/workspaces")
.query(query)
.named("airs.gateway.workspaces.list"),
"ListWorkspacesResponseSchema",
options,
)
.await
}
pub async fn get(
&self,
workspace: &str,
params: &AIGatewayWorkspaceGetOptions,
options: Option<&RequestOptions>,
) -> Result<GatewayWorkspaceDetail> {
common::workspace_ref(workspace)?;
self.plane(params.plane)
.send_contract(
RawRequest::read("/workspaces")
.segment(workspace)?
.named("airs.gateway.workspaces.get"),
"GatewayWorkspaceDetailSchema",
options,
)
.await
}
pub async fn create(
&self,
body: &GatewayWorkspaceCreateRequest,
options: Option<&RequestOptions>,
) -> Result<GatewayWorkspaceCreateResponse> {
self.admin
.send_model(
RawRequest::new(Method::POST, "/workspaces")
.named("airs.gateway.workspaces.create"),
body,
"GatewayWorkspaceCreateRequestSchema",
"GatewayWorkspaceCreateResponseSchema",
options,
)
.await
}
pub async fn update(
&self,
workspace: &str,
body: &GatewayWorkspaceUpdateRequest,
options: Option<&RequestOptions>,
) -> Result<GatewayWriteResponse> {
common::workspace_ref(workspace)?;
self.admin
.send_model(
RawRequest::new(Method::PUT, "/workspaces")
.segment(workspace)?
.named("airs.gateway.workspaces.update"),
body,
"GatewayWorkspaceUpdateRequestSchema",
"GatewayWriteResponseSchema",
options,
)
.await
}
pub async fn delete(&self, workspace: &str, options: Option<&RequestOptions>) -> Result<()> {
common::workspace_ref(workspace)?;
self.admin
.send_empty(
RawRequest::new(Method::DELETE, "/workspaces")
.segment(workspace)?
.named("airs.gateway.workspaces.delete"),
options,
)
.await
}
}