use crate::{CloudClient, Result};
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum EndpointTargetType {
Public,
Private,
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
pub struct CreateEndpointsRedirectionRequest {
pub source_database_id: i32,
pub target_database_id: i32,
pub endpoint_target_type: EndpointTargetType,
#[serde(rename = "duplicateACLs", skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub duplicate_acls: Option<bool>,
pub migration_protection: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum EndpointRedirectionStatus {
Initiated,
Pending,
InProgress,
Completed,
Failed,
Reverted,
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EndpointRedirection {
#[serde(skip_serializing_if = "Option::is_none")]
pub source_endpoint_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_endpoint_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_endpoint_type: Option<EndpointTargetType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_endpoint_type: Option<EndpointTargetType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EndpointsRedirectionResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub redirection_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<EndpointRedirectionStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_database_id: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_database_id: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_revert: Option<bool>,
#[serde(rename = "duplicateACLs", skip_serializing_if = "Option::is_none")]
pub duplicate_acls: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub started_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completed_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reverted_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub endpoints: Option<Vec<EndpointRedirection>>,
}
pub struct EndpointRedirectionsHandler {
client: CloudClient,
}
impl EndpointRedirectionsHandler {
#[must_use]
pub fn new(client: CloudClient) -> Self {
Self { client }
}
pub async fn create(
&self,
request: &CreateEndpointsRedirectionRequest,
) -> Result<EndpointsRedirectionResponse> {
self.client.post("/endpoint-redirections", request).await
}
pub async fn get(&self, redirection_id: &str) -> Result<EndpointsRedirectionResponse> {
self.client
.get(&format!("/endpoint-redirections/{redirection_id}"))
.await
}
pub async fn revert(&self, redirection_id: &str) -> Result<EndpointsRedirectionResponse> {
self.client
.post_empty(&format!("/endpoint-redirections/{redirection_id}/revert"))
.await
}
}