#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::ident::AtIdentifier;
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::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "dev.fudgeu.experimental.atforumv1.feed.question",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Question<S: BosStr = DefaultStr> {
pub content: S,
pub created_at: Datetime,
pub forum: AtIdentifier<S>,
pub is_open: bool,
pub tags: Vec<S>,
pub title: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[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 QuestionGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Question<S>,
}
impl<S: BosStr> Question<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, QuestionRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QuestionRecord;
impl XrpcResp for QuestionRecord {
const NSID: &'static str = "dev.fudgeu.experimental.atforumv1.feed.question";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = QuestionGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<QuestionGetRecordOutput<S>> for Question<S> {
fn from(output: QuestionGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Question<S> {
const NSID: &'static str = "dev.fudgeu.experimental.atforumv1.feed.question";
type Record = QuestionRecord;
}
impl Collection for QuestionRecord {
const NSID: &'static str = "dev.fudgeu.experimental.atforumv1.feed.question";
type Record = QuestionRecord;
}
impl<S: BosStr> LexiconSchema for Question<S> {
fn nsid() -> &'static str {
"dev.fudgeu.experimental.atforumv1.feed.question"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_dev_fudgeu_experimental_atforumv1_feed_question()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.content;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("content"),
max: 10000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.content;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("content"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.tags;
#[allow(unused_comparisons)]
if value.len() > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 20usize,
actual: value.len(),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("title"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod question_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type CreatedAt;
type Content;
type Tags;
type Title;
type Forum;
type IsOpen;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Content = Unset;
type Tags = Unset;
type Title = Unset;
type Forum = Unset;
type IsOpen = Unset;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type CreatedAt = Set<members::created_at>;
type Content = St::Content;
type Tags = St::Tags;
type Title = St::Title;
type Forum = St::Forum;
type IsOpen = St::IsOpen;
}
pub struct SetContent<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetContent<St> {}
impl<St: State> State for SetContent<St> {
type CreatedAt = St::CreatedAt;
type Content = Set<members::content>;
type Tags = St::Tags;
type Title = St::Title;
type Forum = St::Forum;
type IsOpen = St::IsOpen;
}
pub struct SetTags<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTags<St> {}
impl<St: State> State for SetTags<St> {
type CreatedAt = St::CreatedAt;
type Content = St::Content;
type Tags = Set<members::tags>;
type Title = St::Title;
type Forum = St::Forum;
type IsOpen = St::IsOpen;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type CreatedAt = St::CreatedAt;
type Content = St::Content;
type Tags = St::Tags;
type Title = Set<members::title>;
type Forum = St::Forum;
type IsOpen = St::IsOpen;
}
pub struct SetForum<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetForum<St> {}
impl<St: State> State for SetForum<St> {
type CreatedAt = St::CreatedAt;
type Content = St::Content;
type Tags = St::Tags;
type Title = St::Title;
type Forum = Set<members::forum>;
type IsOpen = St::IsOpen;
}
pub struct SetIsOpen<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetIsOpen<St> {}
impl<St: State> State for SetIsOpen<St> {
type CreatedAt = St::CreatedAt;
type Content = St::Content;
type Tags = St::Tags;
type Title = St::Title;
type Forum = St::Forum;
type IsOpen = Set<members::is_open>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct content(());
pub struct tags(());
pub struct title(());
pub struct forum(());
pub struct is_open(());
}
}
pub struct QuestionBuilder<S: BosStr, St: question_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Datetime>,
Option<AtIdentifier<S>>,
Option<bool>,
Option<Vec<S>>,
Option<S>,
Option<Datetime>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Question<S> {
pub fn new() -> QuestionBuilder<S, question_state::Empty> {
QuestionBuilder::new()
}
}
impl<S: BosStr> QuestionBuilder<S, question_state::Empty> {
pub fn new() -> Self {
QuestionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuestionBuilder<S, St>
where
St: question_state::State,
St::Content: question_state::IsUnset,
{
pub fn content(
mut self,
value: impl Into<S>,
) -> QuestionBuilder<S, question_state::SetContent<St>> {
self._fields.0 = Option::Some(value.into());
QuestionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuestionBuilder<S, St>
where
St: question_state::State,
St::CreatedAt: question_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> QuestionBuilder<S, question_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
QuestionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuestionBuilder<S, St>
where
St: question_state::State,
St::Forum: question_state::IsUnset,
{
pub fn forum(
mut self,
value: impl Into<AtIdentifier<S>>,
) -> QuestionBuilder<S, question_state::SetForum<St>> {
self._fields.2 = Option::Some(value.into());
QuestionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuestionBuilder<S, St>
where
St: question_state::State,
St::IsOpen: question_state::IsUnset,
{
pub fn is_open(
mut self,
value: impl Into<bool>,
) -> QuestionBuilder<S, question_state::SetIsOpen<St>> {
self._fields.3 = Option::Some(value.into());
QuestionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuestionBuilder<S, St>
where
St: question_state::State,
St::Tags: question_state::IsUnset,
{
pub fn tags(
mut self,
value: impl Into<Vec<S>>,
) -> QuestionBuilder<S, question_state::SetTags<St>> {
self._fields.4 = Option::Some(value.into());
QuestionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuestionBuilder<S, St>
where
St: question_state::State,
St::Title: question_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> QuestionBuilder<S, question_state::SetTitle<St>> {
self._fields.5 = Option::Some(value.into());
QuestionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: question_state::State> QuestionBuilder<S, St> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> QuestionBuilder<S, St>
where
St: question_state::State,
St::CreatedAt: question_state::IsSet,
St::Content: question_state::IsSet,
St::Tags: question_state::IsSet,
St::Title: question_state::IsSet,
St::Forum: question_state::IsSet,
St::IsOpen: question_state::IsSet,
{
pub fn build(self) -> Question<S> {
Question {
content: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
forum: self._fields.2.unwrap(),
is_open: self._fields.3.unwrap(),
tags: self._fields.4.unwrap(),
title: self._fields.5.unwrap(),
updated_at: self._fields.6,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Question<S> {
Question {
content: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
forum: self._fields.2.unwrap(),
is_open: self._fields.3.unwrap(),
tags: self._fields.4.unwrap(),
title: self._fields.5.unwrap(),
updated_at: self._fields.6,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_dev_fudgeu_experimental_atforumv1_feed_question() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("dev.fudgeu.experimental.atforumv1.feed.question"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static(
"An initial question that starts a discussion",
)),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(vec![
SmolStr::new_static("title"),
SmolStr::new_static("content"),
SmolStr::new_static("createdAt"),
SmolStr::new_static("forum"),
SmolStr::new_static("tags"),
SmolStr::new_static("isOpen"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::String(LexString {
min_length: Some(1usize),
max_length: Some(10000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("forum"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtIdentifier),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("isOpen"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::String(LexString {
min_length: Some(1usize),
max_length: Some(25usize),
..Default::default()
}),
max_length: Some(20usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
min_length: Some(1usize),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}