#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
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::types::value::Data;
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};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "garden.goals.completionDetails",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct CompletionDetails<S: BosStr = DefaultStr> {
pub day: i64,
pub goal_id: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub goal_uri: Option<AtUri<S>>,
pub month: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub photo_alt: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub photo_blob: Option<BlobRef<S>>,
pub updated_at: Datetime,
pub year: i64,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CompletionDetailsGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: CompletionDetails<S>,
}
impl<S: BosStr> CompletionDetails<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, CompletionDetailsRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CompletionDetailsRecord;
impl XrpcResp for CompletionDetailsRecord {
const NSID: &'static str = "garden.goals.completionDetails";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = CompletionDetailsGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<CompletionDetailsGetRecordOutput<S>> for CompletionDetails<S> {
fn from(output: CompletionDetailsGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for CompletionDetails<S> {
const NSID: &'static str = "garden.goals.completionDetails";
type Record = CompletionDetailsRecord;
}
impl Collection for CompletionDetailsRecord {
const NSID: &'static str = "garden.goals.completionDetails";
type Record = CompletionDetailsRecord;
}
impl<S: BosStr> LexiconSchema for CompletionDetails<S> {
fn nsid() -> &'static str {
"garden.goals.completionDetails"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_goals_completionDetails()
}
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_alt {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("photo_alt"),
max: 1000usize,
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(),
});
}
}
}
{
let value = &self.year;
if *value < 1970i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("year"),
min: 1970i64,
actual: *value,
});
}
}
Ok(())
}
}
pub mod completion_details_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 GoalId;
type Year;
type UpdatedAt;
type Month;
type Day;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type GoalId = Unset;
type Year = Unset;
type UpdatedAt = Unset;
type Month = Unset;
type Day = Unset;
}
pub struct SetGoalId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetGoalId<St> {}
impl<St: State> State for SetGoalId<St> {
type GoalId = Set<members::goal_id>;
type Year = St::Year;
type UpdatedAt = St::UpdatedAt;
type Month = St::Month;
type Day = St::Day;
}
pub struct SetYear<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetYear<St> {}
impl<St: State> State for SetYear<St> {
type GoalId = St::GoalId;
type Year = Set<members::year>;
type UpdatedAt = St::UpdatedAt;
type Month = St::Month;
type Day = St::Day;
}
pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
impl<St: State> State for SetUpdatedAt<St> {
type GoalId = St::GoalId;
type Year = St::Year;
type UpdatedAt = Set<members::updated_at>;
type Month = St::Month;
type Day = St::Day;
}
pub struct SetMonth<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMonth<St> {}
impl<St: State> State for SetMonth<St> {
type GoalId = St::GoalId;
type Year = St::Year;
type UpdatedAt = St::UpdatedAt;
type Month = Set<members::month>;
type Day = St::Day;
}
pub struct SetDay<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDay<St> {}
impl<St: State> State for SetDay<St> {
type GoalId = St::GoalId;
type Year = St::Year;
type UpdatedAt = St::UpdatedAt;
type Month = St::Month;
type Day = Set<members::day>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct goal_id(());
pub struct year(());
pub struct updated_at(());
pub struct month(());
pub struct day(());
}
}
pub struct CompletionDetailsBuilder<S: BosStr, St: completion_details_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<i64>,
Option<S>,
Option<AtUri<S>>,
Option<i64>,
Option<S>,
Option<S>,
Option<BlobRef<S>>,
Option<Datetime>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> CompletionDetails<S> {
pub fn new() -> CompletionDetailsBuilder<S, completion_details_state::Empty> {
CompletionDetailsBuilder::new()
}
}
impl<S: BosStr> CompletionDetailsBuilder<S, completion_details_state::Empty> {
pub fn new() -> Self {
CompletionDetailsBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CompletionDetailsBuilder<S, St>
where
St: completion_details_state::State,
St::Day: completion_details_state::IsUnset,
{
pub fn day(
mut self,
value: impl Into<i64>,
) -> CompletionDetailsBuilder<S, completion_details_state::SetDay<St>> {
self._fields.0 = Option::Some(value.into());
CompletionDetailsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CompletionDetailsBuilder<S, St>
where
St: completion_details_state::State,
St::GoalId: completion_details_state::IsUnset,
{
pub fn goal_id(
mut self,
value: impl Into<S>,
) -> CompletionDetailsBuilder<S, completion_details_state::SetGoalId<St>> {
self._fields.1 = Option::Some(value.into());
CompletionDetailsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: completion_details_state::State> CompletionDetailsBuilder<S, St> {
pub fn goal_uri(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_goal_uri(mut self, value: Option<AtUri<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> CompletionDetailsBuilder<S, St>
where
St: completion_details_state::State,
St::Month: completion_details_state::IsUnset,
{
pub fn month(
mut self,
value: impl Into<i64>,
) -> CompletionDetailsBuilder<S, completion_details_state::SetMonth<St>> {
self._fields.3 = Option::Some(value.into());
CompletionDetailsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: completion_details_state::State> CompletionDetailsBuilder<S, St> {
pub fn notes(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_notes(mut self, value: Option<S>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: completion_details_state::State> CompletionDetailsBuilder<S, St> {
pub fn photo_alt(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_photo_alt(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: completion_details_state::State> CompletionDetailsBuilder<S, St> {
pub fn photo_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_photo_blob(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> CompletionDetailsBuilder<S, St>
where
St: completion_details_state::State,
St::UpdatedAt: completion_details_state::IsUnset,
{
pub fn updated_at(
mut self,
value: impl Into<Datetime>,
) -> CompletionDetailsBuilder<S, completion_details_state::SetUpdatedAt<St>> {
self._fields.7 = Option::Some(value.into());
CompletionDetailsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CompletionDetailsBuilder<S, St>
where
St: completion_details_state::State,
St::Year: completion_details_state::IsUnset,
{
pub fn year(
mut self,
value: impl Into<i64>,
) -> CompletionDetailsBuilder<S, completion_details_state::SetYear<St>> {
self._fields.8 = Option::Some(value.into());
CompletionDetailsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CompletionDetailsBuilder<S, St>
where
St: completion_details_state::State,
St::GoalId: completion_details_state::IsSet,
St::Year: completion_details_state::IsSet,
St::UpdatedAt: completion_details_state::IsSet,
St::Month: completion_details_state::IsSet,
St::Day: completion_details_state::IsSet,
{
pub fn build(self) -> CompletionDetails<S> {
CompletionDetails {
day: self._fields.0.unwrap(),
goal_id: self._fields.1.unwrap(),
goal_uri: self._fields.2,
month: self._fields.3.unwrap(),
notes: self._fields.4,
photo_alt: self._fields.5,
photo_blob: self._fields.6,
updated_at: self._fields.7.unwrap(),
year: self._fields.8.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> CompletionDetails<S> {
CompletionDetails {
day: self._fields.0.unwrap(),
goal_id: self._fields.1.unwrap(),
goal_uri: self._fields.2,
month: self._fields.3.unwrap(),
notes: self._fields.4,
photo_alt: self._fields.5,
photo_blob: self._fields.6,
updated_at: self._fields.7.unwrap(),
year: self._fields.8.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_garden_goals_completionDetails() -> 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.completionDetails"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Additional details (notes, photo) for a goal completion 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("updatedAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
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 details record 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 day"),
),
max_length: Some(99usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("photoAlt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Alt text for the photo"),
),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("photoBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when this details record was last updated",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("year"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1970i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}