#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, 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};
use crate::app_protoimsg::chat::community;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CommunityGroup<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_community_group_is_inner_circle")]
pub is_inner_circle: Option<bool>,
pub members: Vec<community::CommunityMember<S>>,
pub name: S,
#[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", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CommunityMember<S: BosStr = DefaultStr> {
pub added_at: Datetime,
pub did: Did<S>,
#[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",
rename = "app.protoimsg.chat.community",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Community<S: BosStr = DefaultStr> {
pub groups: Vec<community::CommunityGroup<S>>,
#[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 CommunityGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Community<S>,
}
impl<S: BosStr> Community<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, CommunityRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for CommunityGroup<S> {
fn nsid() -> &'static str {
"app.protoimsg.chat.community"
}
fn def_name() -> &'static str {
"communityGroup"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_protoimsg_chat_community()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.members;
#[allow(unused_comparisons)]
if value.len() > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("members"),
max: 500usize,
actual: value.len(),
});
}
}
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for CommunityMember<S> {
fn nsid() -> &'static str {
"app.protoimsg.chat.community"
}
fn def_name() -> &'static str {
"communityMember"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_protoimsg_chat_community()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CommunityRecord;
impl XrpcResp for CommunityRecord {
const NSID: &'static str = "app.protoimsg.chat.community";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = CommunityGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<CommunityGetRecordOutput<S>> for Community<S> {
fn from(output: CommunityGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Community<S> {
const NSID: &'static str = "app.protoimsg.chat.community";
type Record = CommunityRecord;
}
impl Collection for CommunityRecord {
const NSID: &'static str = "app.protoimsg.chat.community";
type Record = CommunityRecord;
}
impl<S: BosStr> LexiconSchema for Community<S> {
fn nsid() -> &'static str {
"app.protoimsg.chat.community"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_protoimsg_chat_community()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.groups;
#[allow(unused_comparisons)]
if value.len() > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("groups"),
max: 50usize,
actual: value.len(),
});
}
}
Ok(())
}
}
fn _default_community_group_is_inner_circle() -> Option<bool> {
Some(false)
}
pub mod community_group_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 Members;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Name = Unset;
type Members = Unset;
}
pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetName<St> {}
impl<St: State> State for SetName<St> {
type Name = Set<members::name>;
type Members = St::Members;
}
pub struct SetMembers<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMembers<St> {}
impl<St: State> State for SetMembers<St> {
type Name = St::Name;
type Members = Set<members::members>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct name(());
pub struct members(());
}
}
pub struct CommunityGroupBuilder<S: BosStr, St: community_group_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<bool>, Option<Vec<community::CommunityMember<S>>>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> CommunityGroup<S> {
pub fn new() -> CommunityGroupBuilder<S, community_group_state::Empty> {
CommunityGroupBuilder::new()
}
}
impl<S: BosStr> CommunityGroupBuilder<S, community_group_state::Empty> {
pub fn new() -> Self {
CommunityGroupBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: community_group_state::State> CommunityGroupBuilder<S, St> {
pub fn is_inner_circle(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_is_inner_circle(mut self, value: Option<bool>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> CommunityGroupBuilder<S, St>
where
St: community_group_state::State,
St::Members: community_group_state::IsUnset,
{
pub fn members(
mut self,
value: impl Into<Vec<community::CommunityMember<S>>>,
) -> CommunityGroupBuilder<S, community_group_state::SetMembers<St>> {
self._fields.1 = Option::Some(value.into());
CommunityGroupBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CommunityGroupBuilder<S, St>
where
St: community_group_state::State,
St::Name: community_group_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<S>,
) -> CommunityGroupBuilder<S, community_group_state::SetName<St>> {
self._fields.2 = Option::Some(value.into());
CommunityGroupBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CommunityGroupBuilder<S, St>
where
St: community_group_state::State,
St::Name: community_group_state::IsSet,
St::Members: community_group_state::IsSet,
{
pub fn build(self) -> CommunityGroup<S> {
CommunityGroup {
is_inner_circle: self._fields.0.or_else(|| Some(false)),
members: self._fields.1.unwrap(),
name: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> CommunityGroup<S> {
CommunityGroup {
is_inner_circle: self._fields.0.or_else(|| Some(false)),
members: self._fields.1.unwrap(),
name: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_protoimsg_chat_community() -> 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.protoimsg.chat.community"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("communityGroup"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("A named group of community members."),
),
required: Some(
vec![SmolStr::new_static("name"), SmolStr::new_static("members")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("isInnerCircle"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("members"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("DIDs of group members."),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#communityMember"),
..Default::default()
}),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Group label.")),
max_length: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("communityMember"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("A member in a community group."),
),
required: Some(
vec![SmolStr::new_static("did"), SmolStr::new_static("addedAt")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("addedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this member was added."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("did"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("The member's DID.")),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"The user's community list. Portable across any app implementing the Lexicon.",
),
),
key: Some(CowStr::new_static("literal:self")),
record: LexRecordRecord::Object(LexObject {
required: Some(vec![SmolStr::new_static("groups")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("groups"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Named groups of community members, like AIM's buddy list categories.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#communityGroup"),
..Default::default()
}),
max_length: Some(50usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod community_member_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 Did;
type AddedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Did = Unset;
type AddedAt = Unset;
}
pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDid<St> {}
impl<St: State> State for SetDid<St> {
type Did = Set<members::did>;
type AddedAt = St::AddedAt;
}
pub struct SetAddedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAddedAt<St> {}
impl<St: State> State for SetAddedAt<St> {
type Did = St::Did;
type AddedAt = Set<members::added_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct did(());
pub struct added_at(());
}
}
pub struct CommunityMemberBuilder<S: BosStr, St: community_member_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Datetime>, Option<Did<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> CommunityMember<S> {
pub fn new() -> CommunityMemberBuilder<S, community_member_state::Empty> {
CommunityMemberBuilder::new()
}
}
impl<S: BosStr> CommunityMemberBuilder<S, community_member_state::Empty> {
pub fn new() -> Self {
CommunityMemberBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CommunityMemberBuilder<S, St>
where
St: community_member_state::State,
St::AddedAt: community_member_state::IsUnset,
{
pub fn added_at(
mut self,
value: impl Into<Datetime>,
) -> CommunityMemberBuilder<S, community_member_state::SetAddedAt<St>> {
self._fields.0 = Option::Some(value.into());
CommunityMemberBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CommunityMemberBuilder<S, St>
where
St: community_member_state::State,
St::Did: community_member_state::IsUnset,
{
pub fn did(
mut self,
value: impl Into<Did<S>>,
) -> CommunityMemberBuilder<S, community_member_state::SetDid<St>> {
self._fields.1 = Option::Some(value.into());
CommunityMemberBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CommunityMemberBuilder<S, St>
where
St: community_member_state::State,
St::Did: community_member_state::IsSet,
St::AddedAt: community_member_state::IsSet,
{
pub fn build(self) -> CommunityMember<S> {
CommunityMember {
added_at: self._fields.0.unwrap(),
did: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> CommunityMember<S> {
CommunityMember {
added_at: self._fields.0.unwrap(),
did: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod community_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 Groups;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Groups = Unset;
}
pub struct SetGroups<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetGroups<St> {}
impl<St: State> State for SetGroups<St> {
type Groups = Set<members::groups>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct groups(());
}
}
pub struct CommunityBuilder<S: BosStr, St: community_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Vec<community::CommunityGroup<S>>>,),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Community<S> {
pub fn new() -> CommunityBuilder<S, community_state::Empty> {
CommunityBuilder::new()
}
}
impl<S: BosStr> CommunityBuilder<S, community_state::Empty> {
pub fn new() -> Self {
CommunityBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CommunityBuilder<S, St>
where
St: community_state::State,
St::Groups: community_state::IsUnset,
{
pub fn groups(
mut self,
value: impl Into<Vec<community::CommunityGroup<S>>>,
) -> CommunityBuilder<S, community_state::SetGroups<St>> {
self._fields.0 = Option::Some(value.into());
CommunityBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CommunityBuilder<S, St>
where
St: community_state::State,
St::Groups: community_state::IsSet,
{
pub fn build(self) -> Community<S> {
Community {
groups: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> Community<S> {
Community {
groups: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}