use crate::endpoints::load_balancing::{Origin, Pool};
use crate::framework::endpoint::{EndpointSpec, Method, RequestBody};
use crate::framework::response::ApiSuccess;
use serde::Serialize;
#[derive(Debug)]
pub struct CreatePool<'a> {
pub account_identifier: &'a str,
pub params: Params<'a>,
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct Params<'a> {
pub name: &'a str,
pub origins: &'a [Origin],
#[serde(flatten)]
pub optional_params: Option<OptionalParams<'a>>,
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug, Default)]
pub struct OptionalParams<'a> {
pub description: Option<&'a str>,
pub enabled: Option<bool>,
pub minimum_origins: Option<u8>,
pub monitor: Option<&'a str>,
pub notification_email: Option<&'a str>,
}
impl EndpointSpec for CreatePool<'_> {
type JsonResponse = Pool;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::POST
}
fn path(&self) -> String {
format!("accounts/{}/load_balancers/pools", self.account_identifier)
}
#[inline]
fn body(&self) -> Option<RequestBody> {
let body = serde_json::to_string(&self.params).unwrap();
Some(RequestBody::Json(body))
}
}