use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
pub struct Settings {
pub ttl: Option<u64>,
pub cached_endpoints: Vec<CachedEndpoint>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
pub struct CachedEndpoint {
pub method: Method,
pub path: Path,
}
impl CachedEndpoint {
pub fn new(method: Method, path: Path) -> Self {
Self { method, path }
}
}
impl Path {
pub fn custom_mint(method: &str) -> Self {
Path::Custom(format!("/v1/mint/{}", method))
}
pub fn custom_melt(method: &str) -> Self {
Path::Custom(format!("/v1/melt/{}", method))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
pub enum Method {
Get,
Post,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
pub enum Path {
Swap,
Custom(String),
}
impl Serialize for Path {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let s = match self {
Path::Swap => "/v1/swap",
Path::Custom(custom) => custom.as_str(),
};
serializer.serialize_str(s)
}
}
impl<'de> Deserialize<'de> for Path {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(match s.as_str() {
"/v1/swap" => Path::Swap,
custom => Path::Custom(custom.to_string()),
})
}
}