use std::{borrow::Cow, fmt::Display};
use serde::{Deserialize, Serialize};
use super::endpoint::Endpoint;
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
pub struct VariableId<'a>(Cow<'a, str>);
impl<'a> VariableId<'a> {
pub fn new<T>(id: T) -> Self
where
T: Into<Cow<'a, str>>,
{
Self(id.into())
}
}
impl<'a, T> From<T> for VariableId<'a>
where
T: Into<Cow<'a, str>>,
{
fn from(value: T) -> Self {
Self::new(value)
}
}
impl Display for VariableId<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0)
}
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
pub struct ValueId<'a>(Cow<'a, str>);
impl<'a> ValueId<'a> {
pub fn new<T>(id: T) -> Self
where
T: Into<Cow<'a, str>>,
{
Self(id.into())
}
}
impl<'a, T> From<T> for ValueId<'a>
where
T: Into<Cow<'a, str>>,
{
fn from(value: T) -> Self {
Self::new(value)
}
}
impl Display for ValueId<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0)
}
}
#[derive(Debug, Builder, Clone)]
#[builder(setter(into, strip_option))]
pub struct Variable<'a> {
#[doc = r"Variable ID"]
id: VariableId<'a>,
}
impl Variable<'_> {
pub fn builder<'a>() -> VariableBuilder<'a> {
VariableBuilder::default()
}
}
impl Endpoint for Variable<'_> {
fn endpoint(&self) -> Cow<'static, str> {
format!("/variables/{}", self.id).into()
}
}