use crate::endpoints::load_balancing::{Origin, Pool};
use crate::framework::endpoint::{EndpointSpec, Method};
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<'a> EndpointSpec<Pool> for CreatePool<'a> {
fn method(&self) -> Method {
Method::POST
}
fn path(&self) -> String {
format!("accounts/{}/load_balancers/pools", self.account_identifier)
}
#[inline]
fn body(&self) -> Option<String> {
let body = serde_json::to_string(&self.params).unwrap();
Some(body)
}
}