#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Goal<'a> {
pub created_at: jacquard_common::types::string::Datetime,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
pub end_date: std::option::Option<jacquard_common::types::string::Datetime>,
#[serde(borrow)]
pub metric: GoalMetric<'a>,
#[serde(borrow)]
pub period: GoalPeriod<'a>,
pub start_date: jacquard_common::types::string::Datetime,
pub target_value: i64,
}
pub mod goal_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type TargetValue;
type CreatedAt;
type StartDate;
type Metric;
type Period;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type TargetValue = Unset;
type CreatedAt = Unset;
type StartDate = Unset;
type Metric = Unset;
type Period = Unset;
}
pub struct SetTargetValue<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTargetValue<S> {}
impl<S: State> State for SetTargetValue<S> {
type TargetValue = Set<members::target_value>;
type CreatedAt = S::CreatedAt;
type StartDate = S::StartDate;
type Metric = S::Metric;
type Period = S::Period;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type TargetValue = S::TargetValue;
type CreatedAt = Set<members::created_at>;
type StartDate = S::StartDate;
type Metric = S::Metric;
type Period = S::Period;
}
pub struct SetStartDate<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetStartDate<S> {}
impl<S: State> State for SetStartDate<S> {
type TargetValue = S::TargetValue;
type CreatedAt = S::CreatedAt;
type StartDate = Set<members::start_date>;
type Metric = S::Metric;
type Period = S::Period;
}
pub struct SetMetric<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMetric<S> {}
impl<S: State> State for SetMetric<S> {
type TargetValue = S::TargetValue;
type CreatedAt = S::CreatedAt;
type StartDate = S::StartDate;
type Metric = Set<members::metric>;
type Period = S::Period;
}
pub struct SetPeriod<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPeriod<S> {}
impl<S: State> State for SetPeriod<S> {
type TargetValue = S::TargetValue;
type CreatedAt = S::CreatedAt;
type StartDate = S::StartDate;
type Metric = S::Metric;
type Period = Set<members::period>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct target_value(());
pub struct created_at(());
pub struct start_date(());
pub struct metric(());
pub struct period(());
}
}
pub struct GoalBuilder<'a, S: goal_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<jacquard_common::types::string::Datetime>,
::core::option::Option<jacquard_common::types::string::Datetime>,
::core::option::Option<GoalMetric<'a>>,
::core::option::Option<GoalPeriod<'a>>,
::core::option::Option<jacquard_common::types::string::Datetime>,
::core::option::Option<i64>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> Goal<'a> {
pub fn new() -> GoalBuilder<'a, goal_state::Empty> {
GoalBuilder::new()
}
}
impl<'a> GoalBuilder<'a, goal_state::Empty> {
pub fn new() -> Self {
GoalBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (None, None, None, None, None, None),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::CreatedAt: goal_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<jacquard_common::types::string::Datetime>,
) -> GoalBuilder<'a, goal_state::SetCreatedAt<S>> {
self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
GoalBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn end_date(
mut self,
value: impl Into<Option<jacquard_common::types::string::Datetime>>,
) -> Self {
self.__unsafe_private_named.1 = value.into();
self
}
pub fn maybe_end_date(
mut self,
value: Option<jacquard_common::types::string::Datetime>,
) -> Self {
self.__unsafe_private_named.1 = value;
self
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::Metric: goal_state::IsUnset,
{
pub fn metric(
mut self,
value: impl Into<GoalMetric<'a>>,
) -> GoalBuilder<'a, goal_state::SetMetric<S>> {
self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
GoalBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::Period: goal_state::IsUnset,
{
pub fn period(
mut self,
value: impl Into<GoalPeriod<'a>>,
) -> GoalBuilder<'a, goal_state::SetPeriod<S>> {
self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
GoalBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::StartDate: goal_state::IsUnset,
{
pub fn start_date(
mut self,
value: impl Into<jacquard_common::types::string::Datetime>,
) -> GoalBuilder<'a, goal_state::SetStartDate<S>> {
self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into());
GoalBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::TargetValue: goal_state::IsUnset,
{
pub fn target_value(
mut self,
value: impl Into<i64>,
) -> GoalBuilder<'a, goal_state::SetTargetValue<S>> {
self.__unsafe_private_named.5 = ::core::option::Option::Some(value.into());
GoalBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::TargetValue: goal_state::IsSet,
S::CreatedAt: goal_state::IsSet,
S::StartDate: goal_state::IsSet,
S::Metric: goal_state::IsSet,
S::Period: goal_state::IsSet,
{
pub fn build(self) -> Goal<'a> {
Goal {
created_at: self.__unsafe_private_named.0.unwrap(),
end_date: self.__unsafe_private_named.1,
metric: self.__unsafe_private_named.2.unwrap(),
period: self.__unsafe_private_named.3.unwrap(),
start_date: self.__unsafe_private_named.4.unwrap(),
target_value: self.__unsafe_private_named.5.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: std::collections::BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Goal<'a> {
Goal {
created_at: self.__unsafe_private_named.0.unwrap(),
end_date: self.__unsafe_private_named.1,
metric: self.__unsafe_private_named.2.unwrap(),
period: self.__unsafe_private_named.3.unwrap(),
start_date: self.__unsafe_private_named.4.unwrap(),
target_value: self.__unsafe_private_named.5.unwrap(),
extra_data: Some(extra_data),
}
}
}
impl<'a> Goal<'a> {
pub fn uri(
uri: impl Into<jacquard_common::CowStr<'a>>,
) -> Result<
jacquard_common::types::uri::RecordUri<'a, GoalRecord>,
jacquard_common::types::uri::UriError,
> {
jacquard_common::types::uri::RecordUri::try_from_uri(
jacquard_common::types::string::AtUri::new_cow(uri.into())?,
)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GoalMetric<'a> {
Distance,
Workouts,
Duration,
Pace,
Other(jacquard_common::CowStr<'a>),
}
impl<'a> GoalMetric<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Distance => "distance",
Self::Workouts => "workouts",
Self::Duration => "duration",
Self::Pace => "pace",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for GoalMetric<'a> {
fn from(s: &'a str) -> Self {
match s {
"distance" => Self::Distance,
"workouts" => Self::Workouts,
"duration" => Self::Duration,
"pace" => Self::Pace,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> From<String> for GoalMetric<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"distance" => Self::Distance,
"workouts" => Self::Workouts,
"duration" => Self::Duration,
"pace" => Self::Pace,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for GoalMetric<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for GoalMetric<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for GoalMetric<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for GoalMetric<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for GoalMetric<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for GoalMetric<'_> {
type Output = GoalMetric<'static>;
fn into_static(self) -> Self::Output {
match self {
GoalMetric::Distance => GoalMetric::Distance,
GoalMetric::Workouts => GoalMetric::Workouts,
GoalMetric::Duration => GoalMetric::Duration,
GoalMetric::Pace => GoalMetric::Pace,
GoalMetric::Other(v) => GoalMetric::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GoalPeriod<'a> {
Weekly,
Monthly,
Yearly,
Other(jacquard_common::CowStr<'a>),
}
impl<'a> GoalPeriod<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Weekly => "weekly",
Self::Monthly => "monthly",
Self::Yearly => "yearly",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for GoalPeriod<'a> {
fn from(s: &'a str) -> Self {
match s {
"weekly" => Self::Weekly,
"monthly" => Self::Monthly,
"yearly" => Self::Yearly,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> From<String> for GoalPeriod<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"weekly" => Self::Weekly,
"monthly" => Self::Monthly,
"yearly" => Self::Yearly,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for GoalPeriod<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for GoalPeriod<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for GoalPeriod<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for GoalPeriod<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for GoalPeriod<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for GoalPeriod<'_> {
type Output = GoalPeriod<'static>;
fn into_static(self) -> Self::Output {
match self {
GoalPeriod::Weekly => GoalPeriod::Weekly,
GoalPeriod::Monthly => GoalPeriod::Monthly,
GoalPeriod::Yearly => GoalPeriod::Yearly,
GoalPeriod::Other(v) => GoalPeriod::Other(v.into_static()),
}
}
}
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GoalGetRecordOutput<'a> {
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
#[serde(borrow)]
pub uri: jacquard_common::types::string::AtUri<'a>,
#[serde(borrow)]
pub value: Goal<'a>,
}
impl From<GoalGetRecordOutput<'_>> for Goal<'_> {
fn from(output: GoalGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl jacquard_common::types::collection::Collection for Goal<'_> {
const NSID: &'static str = "app.fitsky.goal";
type Record = GoalRecord;
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct GoalRecord;
impl jacquard_common::xrpc::XrpcResp for GoalRecord {
const NSID: &'static str = "app.fitsky.goal";
const ENCODING: &'static str = "application/json";
type Output<'de> = GoalGetRecordOutput<'de>;
type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
}
impl jacquard_common::types::collection::Collection for GoalRecord {
const NSID: &'static str = "app.fitsky.goal";
type Record = GoalRecord;
}
impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Goal<'a> {
fn nsid() -> &'static str {
"app.fitsky.goal"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
lexicon_doc_app_fitsky_goal()
}
fn validate(
&self,
) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
{
let value = &self.metric;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"metric",
),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.period;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"period",
),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.target_value;
if *value < 0i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Minimum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"target_value",
),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
fn lexicon_doc_app_fitsky_goal() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
::jacquard_lexicon::lexicon::LexiconDoc {
lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
id: ::jacquard_common::CowStr::new_static("app.fitsky.goal"),
revision: None,
description: None,
defs: {
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static("main"),
::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
description: Some(
::jacquard_common::CowStr::new_static(
"A fitness goal to track progress against",
),
),
key: Some(::jacquard_common::CowStr::new_static("tid")),
record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
description: None,
required: Some(
vec![
::jacquard_common::deps::smol_str::SmolStr::new_static("metric"),
::jacquard_common::deps::smol_str::SmolStr::new_static("targetValue"),
::jacquard_common::deps::smol_str::SmolStr::new_static("period"),
::jacquard_common::deps::smol_str::SmolStr::new_static("startDate"),
::jacquard_common::deps::smol_str::SmolStr::new_static("createdAt")
],
),
nullable: None,
properties: {
#[allow(unused_mut)]
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"createdAt",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"endDate",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"metric",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: None,
default: None,
min_length: None,
max_length: Some(64usize),
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"period",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: None,
default: None,
min_length: None,
max_length: Some(64usize),
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"startDate",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"targetValue",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
description: None,
default: None,
minimum: Some(0i64),
maximum: None,
r#enum: None,
r#const: None,
}),
);
map
},
}),
}),
);
map
},
}
}