#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::app_fitsky::workout_plan;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct WorkoutPlan<'a> {
pub created_at: Datetime,
#[serde(borrow)]
pub exercises: Vec<workout_plan::PlanExercise<'a>>,
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub og_image: Option<BlobRef<'a>>,
#[serde(borrow)]
pub r#type: WorkoutPlanType<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WorkoutPlanType<'a> {
Weightlifting,
Bodyweight,
Yoga,
Hiit,
Other(CowStr<'a>),
}
impl<'a> WorkoutPlanType<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Weightlifting => "weightlifting",
Self::Bodyweight => "bodyweight",
Self::Yoga => "yoga",
Self::Hiit => "hiit",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for WorkoutPlanType<'a> {
fn from(s: &'a str) -> Self {
match s {
"weightlifting" => Self::Weightlifting,
"bodyweight" => Self::Bodyweight,
"yoga" => Self::Yoga,
"hiit" => Self::Hiit,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for WorkoutPlanType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"weightlifting" => Self::Weightlifting,
"bodyweight" => Self::Bodyweight,
"yoga" => Self::Yoga,
"hiit" => Self::Hiit,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for WorkoutPlanType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for WorkoutPlanType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for WorkoutPlanType<'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 WorkoutPlanType<'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 WorkoutPlanType<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for WorkoutPlanType<'_> {
type Output = WorkoutPlanType<'static>;
fn into_static(self) -> Self::Output {
match self {
WorkoutPlanType::Weightlifting => WorkoutPlanType::Weightlifting,
WorkoutPlanType::Bodyweight => WorkoutPlanType::Bodyweight,
WorkoutPlanType::Yoga => WorkoutPlanType::Yoga,
WorkoutPlanType::Hiit => WorkoutPlanType::Hiit,
WorkoutPlanType::Other(v) => WorkoutPlanType::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct WorkoutPlanGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: WorkoutPlan<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PlanExercise<'a> {
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub notes: Option<CowStr<'a>>,
pub target_reps: i64,
pub target_sets: i64,
}
impl<'a> WorkoutPlan<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, WorkoutPlanRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct WorkoutPlanRecord;
impl XrpcResp for WorkoutPlanRecord {
const NSID: &'static str = "app.fitsky.workoutPlan";
const ENCODING: &'static str = "application/json";
type Output<'de> = WorkoutPlanGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<WorkoutPlanGetRecordOutput<'_>> for WorkoutPlan<'_> {
fn from(output: WorkoutPlanGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for WorkoutPlan<'_> {
const NSID: &'static str = "app.fitsky.workoutPlan";
type Record = WorkoutPlanRecord;
}
impl Collection for WorkoutPlanRecord {
const NSID: &'static str = "app.fitsky.workoutPlan";
type Record = WorkoutPlanRecord;
}
impl<'a> LexiconSchema for WorkoutPlan<'a> {
fn nsid() -> &'static str {
"app.fitsky.workoutPlan"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_fitsky_workoutPlan()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.og_image {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("og_image"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.og_image {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/png", "image/jpeg", "image/webp"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("og_image"),
accepted: vec![
"image/png".to_string(), "image/jpeg".to_string(),
"image/webp".to_string()
],
actual: mime.to_string(),
});
}
}
}
{
let value = &self.r#type;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("type"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for PlanExercise<'a> {
fn nsid() -> &'static str {
"app.fitsky.workoutPlan"
}
fn def_name() -> &'static str {
"planExercise"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_fitsky_workoutPlan()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.notes {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("notes"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.target_reps;
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("target_reps"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.target_sets;
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("target_sets"),
min: 1i64,
actual: *value,
});
}
}
Ok(())
}
}
pub mod workout_plan_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 CreatedAt;
type Type;
type Exercises;
type Name;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Type = Unset;
type Exercises = Unset;
type Name = Unset;
}
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 CreatedAt = Set<members::created_at>;
type Type = S::Type;
type Exercises = S::Exercises;
type Name = S::Name;
}
pub struct SetType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetType<S> {}
impl<S: State> State for SetType<S> {
type CreatedAt = S::CreatedAt;
type Type = Set<members::r#type>;
type Exercises = S::Exercises;
type Name = S::Name;
}
pub struct SetExercises<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetExercises<S> {}
impl<S: State> State for SetExercises<S> {
type CreatedAt = S::CreatedAt;
type Type = S::Type;
type Exercises = Set<members::exercises>;
type Name = S::Name;
}
pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetName<S> {}
impl<S: State> State for SetName<S> {
type CreatedAt = S::CreatedAt;
type Type = S::Type;
type Exercises = S::Exercises;
type Name = Set<members::name>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct r#type(());
pub struct exercises(());
pub struct name(());
}
}
pub struct WorkoutPlanBuilder<'a, S: workout_plan_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<Vec<workout_plan::PlanExercise<'a>>>,
Option<CowStr<'a>>,
Option<BlobRef<'a>>,
Option<WorkoutPlanType<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> WorkoutPlan<'a> {
pub fn new() -> WorkoutPlanBuilder<'a, workout_plan_state::Empty> {
WorkoutPlanBuilder::new()
}
}
impl<'a> WorkoutPlanBuilder<'a, workout_plan_state::Empty> {
pub fn new() -> Self {
WorkoutPlanBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> WorkoutPlanBuilder<'a, S>
where
S: workout_plan_state::State,
S::CreatedAt: workout_plan_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> WorkoutPlanBuilder<'a, workout_plan_state::SetCreatedAt<S>> {
self._fields.0 = Option::Some(value.into());
WorkoutPlanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> WorkoutPlanBuilder<'a, S>
where
S: workout_plan_state::State,
S::Exercises: workout_plan_state::IsUnset,
{
pub fn exercises(
mut self,
value: impl Into<Vec<workout_plan::PlanExercise<'a>>>,
) -> WorkoutPlanBuilder<'a, workout_plan_state::SetExercises<S>> {
self._fields.1 = Option::Some(value.into());
WorkoutPlanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> WorkoutPlanBuilder<'a, S>
where
S: workout_plan_state::State,
S::Name: workout_plan_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> WorkoutPlanBuilder<'a, workout_plan_state::SetName<S>> {
self._fields.2 = Option::Some(value.into());
WorkoutPlanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: workout_plan_state::State> WorkoutPlanBuilder<'a, S> {
pub fn og_image(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_og_image(mut self, value: Option<BlobRef<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> WorkoutPlanBuilder<'a, S>
where
S: workout_plan_state::State,
S::Type: workout_plan_state::IsUnset,
{
pub fn r#type(
mut self,
value: impl Into<WorkoutPlanType<'a>>,
) -> WorkoutPlanBuilder<'a, workout_plan_state::SetType<S>> {
self._fields.4 = Option::Some(value.into());
WorkoutPlanBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> WorkoutPlanBuilder<'a, S>
where
S: workout_plan_state::State,
S::CreatedAt: workout_plan_state::IsSet,
S::Type: workout_plan_state::IsSet,
S::Exercises: workout_plan_state::IsSet,
S::Name: workout_plan_state::IsSet,
{
pub fn build(self) -> WorkoutPlan<'a> {
WorkoutPlan {
created_at: self._fields.0.unwrap(),
exercises: self._fields.1.unwrap(),
name: self._fields.2.unwrap(),
og_image: self._fields.3,
r#type: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> WorkoutPlan<'a> {
WorkoutPlan {
created_at: self._fields.0.unwrap(),
exercises: self._fields.1.unwrap(),
name: self._fields.2.unwrap(),
og_image: self._fields.3,
r#type: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_fitsky_workoutPlan() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("app.fitsky.workoutPlan"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("A reusable workout plan template"),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"), SmolStr::new_static("type"),
SmolStr::new_static("exercises"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("exercises"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#planExercise"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
max_length: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("ogImage"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString {
max_length: Some(64usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("planExercise"),
LexUserType::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"),
SmolStr::new_static("targetSets"),
SmolStr::new_static("targetReps")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
max_length: Some(128usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notes"),
LexObjectProperty::String(LexString {
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("targetReps"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("targetSets"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod plan_exercise_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 Name;
type TargetSets;
type TargetReps;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Name = Unset;
type TargetSets = Unset;
type TargetReps = Unset;
}
pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetName<S> {}
impl<S: State> State for SetName<S> {
type Name = Set<members::name>;
type TargetSets = S::TargetSets;
type TargetReps = S::TargetReps;
}
pub struct SetTargetSets<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTargetSets<S> {}
impl<S: State> State for SetTargetSets<S> {
type Name = S::Name;
type TargetSets = Set<members::target_sets>;
type TargetReps = S::TargetReps;
}
pub struct SetTargetReps<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTargetReps<S> {}
impl<S: State> State for SetTargetReps<S> {
type Name = S::Name;
type TargetSets = S::TargetSets;
type TargetReps = Set<members::target_reps>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct name(());
pub struct target_sets(());
pub struct target_reps(());
}
}
pub struct PlanExerciseBuilder<'a, S: plan_exercise_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<i64>, Option<i64>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> PlanExercise<'a> {
pub fn new() -> PlanExerciseBuilder<'a, plan_exercise_state::Empty> {
PlanExerciseBuilder::new()
}
}
impl<'a> PlanExerciseBuilder<'a, plan_exercise_state::Empty> {
pub fn new() -> Self {
PlanExerciseBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> PlanExerciseBuilder<'a, S>
where
S: plan_exercise_state::State,
S::Name: plan_exercise_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> PlanExerciseBuilder<'a, plan_exercise_state::SetName<S>> {
self._fields.0 = Option::Some(value.into());
PlanExerciseBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: plan_exercise_state::State> PlanExerciseBuilder<'a, S> {
pub fn notes(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_notes(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> PlanExerciseBuilder<'a, S>
where
S: plan_exercise_state::State,
S::TargetReps: plan_exercise_state::IsUnset,
{
pub fn target_reps(
mut self,
value: impl Into<i64>,
) -> PlanExerciseBuilder<'a, plan_exercise_state::SetTargetReps<S>> {
self._fields.2 = Option::Some(value.into());
PlanExerciseBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> PlanExerciseBuilder<'a, S>
where
S: plan_exercise_state::State,
S::TargetSets: plan_exercise_state::IsUnset,
{
pub fn target_sets(
mut self,
value: impl Into<i64>,
) -> PlanExerciseBuilder<'a, plan_exercise_state::SetTargetSets<S>> {
self._fields.3 = Option::Some(value.into());
PlanExerciseBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> PlanExerciseBuilder<'a, S>
where
S: plan_exercise_state::State,
S::Name: plan_exercise_state::IsSet,
S::TargetSets: plan_exercise_state::IsSet,
S::TargetReps: plan_exercise_state::IsSet,
{
pub fn build(self) -> PlanExercise<'a> {
PlanExercise {
name: self._fields.0.unwrap(),
notes: self._fields.1,
target_reps: self._fields.2.unwrap(),
target_sets: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> PlanExercise<'a> {
PlanExercise {
name: self._fields.0.unwrap(),
notes: self._fields.1,
target_reps: self._fields.2.unwrap(),
target_sets: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}