#[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};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", rename = "garden.goals.completion", tag = "$type")]
pub struct Completion<'a> {
pub completed_at: Datetime,
pub day: i64,
#[serde(borrow)]
pub goal_id: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub goal_uri: Option<AtUri<'a>>,
pub month: i64,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub notes: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub photo_blob: Option<BlobRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sequence_num: Option<i64>,
pub year: i64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CompletionGetRecordOutput<'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: Completion<'a>,
}
impl<'a> Completion<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, CompletionRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CompletionRecord;
impl XrpcResp for CompletionRecord {
const NSID: &'static str = "garden.goals.completion";
const ENCODING: &'static str = "application/json";
type Output<'de> = CompletionGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<CompletionGetRecordOutput<'_>> for Completion<'_> {
fn from(output: CompletionGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Completion<'_> {
const NSID: &'static str = "garden.goals.completion";
type Record = CompletionRecord;
}
impl Collection for CompletionRecord {
const NSID: &'static str = "garden.goals.completion";
type Record = CompletionRecord;
}
impl<'a> LexiconSchema for Completion<'a> {
fn nsid() -> &'static str {
"garden.goals.completion"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_goals_completion()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.day;
if *value > 31i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("day"),
max: 31i64,
actual: *value,
});
}
}
{
let value = &self.day;
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("day"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.goal_id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("goal_id"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.month;
if *value > 12i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("month"),
max: 12i64,
actual: *value,
});
}
}
{
let value = &self.month;
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("month"),
min: 1i64,
actual: *value,
});
}
}
if let Some(ref value) = self.notes {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 99usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("notes"),
max: 99usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.photo_blob {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("photo_blob"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.photo_blob {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
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("photo_blob"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.sequence_num {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("sequence_num"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.year;
if *value < 1970i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("year"),
min: 1970i64,
actual: *value,
});
}
}
Ok(())
}
}
pub mod completion_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 Month;
type CompletedAt;
type GoalId;
type Year;
type Day;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Month = Unset;
type CompletedAt = Unset;
type GoalId = Unset;
type Year = Unset;
type Day = Unset;
}
pub struct SetMonth<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMonth<S> {}
impl<S: State> State for SetMonth<S> {
type Month = Set<members::month>;
type CompletedAt = S::CompletedAt;
type GoalId = S::GoalId;
type Year = S::Year;
type Day = S::Day;
}
pub struct SetCompletedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCompletedAt<S> {}
impl<S: State> State for SetCompletedAt<S> {
type Month = S::Month;
type CompletedAt = Set<members::completed_at>;
type GoalId = S::GoalId;
type Year = S::Year;
type Day = S::Day;
}
pub struct SetGoalId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetGoalId<S> {}
impl<S: State> State for SetGoalId<S> {
type Month = S::Month;
type CompletedAt = S::CompletedAt;
type GoalId = Set<members::goal_id>;
type Year = S::Year;
type Day = S::Day;
}
pub struct SetYear<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetYear<S> {}
impl<S: State> State for SetYear<S> {
type Month = S::Month;
type CompletedAt = S::CompletedAt;
type GoalId = S::GoalId;
type Year = Set<members::year>;
type Day = S::Day;
}
pub struct SetDay<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetDay<S> {}
impl<S: State> State for SetDay<S> {
type Month = S::Month;
type CompletedAt = S::CompletedAt;
type GoalId = S::GoalId;
type Year = S::Year;
type Day = Set<members::day>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct month(());
pub struct completed_at(());
pub struct goal_id(());
pub struct year(());
pub struct day(());
}
}
pub struct CompletionBuilder<'a, S: completion_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<i64>,
Option<CowStr<'a>>,
Option<AtUri<'a>>,
Option<i64>,
Option<CowStr<'a>>,
Option<BlobRef<'a>>,
Option<i64>,
Option<i64>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Completion<'a> {
pub fn new() -> CompletionBuilder<'a, completion_state::Empty> {
CompletionBuilder::new()
}
}
impl<'a> CompletionBuilder<'a, completion_state::Empty> {
pub fn new() -> Self {
CompletionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> CompletionBuilder<'a, S>
where
S: completion_state::State,
S::CompletedAt: completion_state::IsUnset,
{
pub fn completed_at(
mut self,
value: impl Into<Datetime>,
) -> CompletionBuilder<'a, completion_state::SetCompletedAt<S>> {
self._fields.0 = Option::Some(value.into());
CompletionBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CompletionBuilder<'a, S>
where
S: completion_state::State,
S::Day: completion_state::IsUnset,
{
pub fn day(
mut self,
value: impl Into<i64>,
) -> CompletionBuilder<'a, completion_state::SetDay<S>> {
self._fields.1 = Option::Some(value.into());
CompletionBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CompletionBuilder<'a, S>
where
S: completion_state::State,
S::GoalId: completion_state::IsUnset,
{
pub fn goal_id(
mut self,
value: impl Into<CowStr<'a>>,
) -> CompletionBuilder<'a, completion_state::SetGoalId<S>> {
self._fields.2 = Option::Some(value.into());
CompletionBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: completion_state::State> CompletionBuilder<'a, S> {
pub fn goal_uri(mut self, value: impl Into<Option<AtUri<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_goal_uri(mut self, value: Option<AtUri<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> CompletionBuilder<'a, S>
where
S: completion_state::State,
S::Month: completion_state::IsUnset,
{
pub fn month(
mut self,
value: impl Into<i64>,
) -> CompletionBuilder<'a, completion_state::SetMonth<S>> {
self._fields.4 = Option::Some(value.into());
CompletionBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: completion_state::State> CompletionBuilder<'a, S> {
pub fn notes(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_notes(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: completion_state::State> CompletionBuilder<'a, S> {
pub fn photo_blob(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_photo_blob(mut self, value: Option<BlobRef<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S: completion_state::State> CompletionBuilder<'a, S> {
pub fn sequence_num(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_sequence_num(mut self, value: Option<i64>) -> Self {
self._fields.7 = value;
self
}
}
impl<'a, S> CompletionBuilder<'a, S>
where
S: completion_state::State,
S::Year: completion_state::IsUnset,
{
pub fn year(
mut self,
value: impl Into<i64>,
) -> CompletionBuilder<'a, completion_state::SetYear<S>> {
self._fields.8 = Option::Some(value.into());
CompletionBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CompletionBuilder<'a, S>
where
S: completion_state::State,
S::Month: completion_state::IsSet,
S::CompletedAt: completion_state::IsSet,
S::GoalId: completion_state::IsSet,
S::Year: completion_state::IsSet,
S::Day: completion_state::IsSet,
{
pub fn build(self) -> Completion<'a> {
Completion {
completed_at: self._fields.0.unwrap(),
day: self._fields.1.unwrap(),
goal_id: self._fields.2.unwrap(),
goal_uri: self._fields.3,
month: self._fields.4.unwrap(),
notes: self._fields.5,
photo_blob: self._fields.6,
sequence_num: self._fields.7,
year: self._fields.8.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>,
>,
) -> Completion<'a> {
Completion {
completed_at: self._fields.0.unwrap(),
day: self._fields.1.unwrap(),
goal_id: self._fields.2.unwrap(),
goal_uri: self._fields.3,
month: self._fields.4.unwrap(),
notes: self._fields.5,
photo_blob: self._fields.6,
sequence_num: self._fields.7,
year: self._fields.8.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_garden_goals_completion() -> 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("garden.goals.completion"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A record of completing a goal on a specific day.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("goalId"), SmolStr::new_static("year"),
SmolStr::new_static("month"), SmolStr::new_static("day"),
SmolStr::new_static("completedAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("completedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when the completion was recorded",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("day"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(31i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("goalId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"UUID of the goal this completion belongs to",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("goalUri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT Protocol URI reference to the goal record",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("month"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(12i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notes"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Optional notes for this completion"),
),
max_length: Some(99usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("photoBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("sequenceNum"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("year"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1970i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}