#[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::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_protoimsg::chat::room;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Room<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub category: Option<CowStr<'a>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(borrow)]
pub purpose: RoomPurpose<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub settings: Option<room::RoomSettings<'a>>,
#[serde(borrow)]
pub topic: CowStr<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RoomPurpose<'a> {
Discussion,
Event,
Community,
Support,
Other(CowStr<'a>),
}
impl<'a> RoomPurpose<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Discussion => "discussion",
Self::Event => "event",
Self::Community => "community",
Self::Support => "support",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for RoomPurpose<'a> {
fn from(s: &'a str) -> Self {
match s {
"discussion" => Self::Discussion,
"event" => Self::Event,
"community" => Self::Community,
"support" => Self::Support,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for RoomPurpose<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"discussion" => Self::Discussion,
"event" => Self::Event,
"community" => Self::Community,
"support" => Self::Support,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for RoomPurpose<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for RoomPurpose<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for RoomPurpose<'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 RoomPurpose<'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 RoomPurpose<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for RoomPurpose<'_> {
type Output = RoomPurpose<'static>;
fn into_static(self) -> Self::Output {
match self {
RoomPurpose::Discussion => RoomPurpose::Discussion,
RoomPurpose::Event => RoomPurpose::Event,
RoomPurpose::Community => RoomPurpose::Community,
RoomPurpose::Support => RoomPurpose::Support,
RoomPurpose::Other(v) => RoomPurpose::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RoomGetRecordOutput<'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: Room<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RoomSettings<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_room_settings_allowlist_enabled")]
pub allowlist_enabled: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_room_settings_min_account_age_days")]
pub min_account_age_days: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_room_settings_slow_mode_seconds")]
pub slow_mode_seconds: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub visibility: Option<RoomSettingsVisibility<'a>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RoomSettingsVisibility<'a> {
Public,
Unlisted,
Private,
Other(CowStr<'a>),
}
impl<'a> RoomSettingsVisibility<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Public => "public",
Self::Unlisted => "unlisted",
Self::Private => "private",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for RoomSettingsVisibility<'a> {
fn from(s: &'a str) -> Self {
match s {
"public" => Self::Public,
"unlisted" => Self::Unlisted,
"private" => Self::Private,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for RoomSettingsVisibility<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"public" => Self::Public,
"unlisted" => Self::Unlisted,
"private" => Self::Private,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for RoomSettingsVisibility<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for RoomSettingsVisibility<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for RoomSettingsVisibility<'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 RoomSettingsVisibility<'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 RoomSettingsVisibility<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for RoomSettingsVisibility<'_> {
type Output = RoomSettingsVisibility<'static>;
fn into_static(self) -> Self::Output {
match self {
RoomSettingsVisibility::Public => RoomSettingsVisibility::Public,
RoomSettingsVisibility::Unlisted => RoomSettingsVisibility::Unlisted,
RoomSettingsVisibility::Private => RoomSettingsVisibility::Private,
RoomSettingsVisibility::Other(v) => {
RoomSettingsVisibility::Other(v.into_static())
}
}
}
}
impl<'a> Room<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, RoomRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RoomRecord;
impl XrpcResp for RoomRecord {
const NSID: &'static str = "app.protoimsg.chat.room";
const ENCODING: &'static str = "application/json";
type Output<'de> = RoomGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<RoomGetRecordOutput<'_>> for Room<'_> {
fn from(output: RoomGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Room<'_> {
const NSID: &'static str = "app.protoimsg.chat.room";
type Record = RoomRecord;
}
impl Collection for RoomRecord {
const NSID: &'static str = "app.protoimsg.chat.room";
type Record = RoomRecord;
}
impl<'a> LexiconSchema for Room<'a> {
fn nsid() -> &'static str {
"app.protoimsg.chat.room"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_protoimsg_chat_room()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.category {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("category"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
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()),
});
}
}
{
let value = &self.topic;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("topic"),
max: 200usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for RoomSettings<'a> {
fn nsid() -> &'static str {
"app.protoimsg.chat.room"
}
fn def_name() -> &'static str {
"roomSettings"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_protoimsg_chat_room()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.min_account_age_days {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("min_account_age_days"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.slow_mode_seconds {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("slow_mode_seconds"),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
pub mod room_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 Purpose;
type Name;
type CreatedAt;
type Topic;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Purpose = Unset;
type Name = Unset;
type CreatedAt = Unset;
type Topic = Unset;
}
pub struct SetPurpose<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPurpose<S> {}
impl<S: State> State for SetPurpose<S> {
type Purpose = Set<members::purpose>;
type Name = S::Name;
type CreatedAt = S::CreatedAt;
type Topic = S::Topic;
}
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 Purpose = S::Purpose;
type Name = Set<members::name>;
type CreatedAt = S::CreatedAt;
type Topic = S::Topic;
}
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 Purpose = S::Purpose;
type Name = S::Name;
type CreatedAt = Set<members::created_at>;
type Topic = S::Topic;
}
pub struct SetTopic<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTopic<S> {}
impl<S: State> State for SetTopic<S> {
type Purpose = S::Purpose;
type Name = S::Name;
type CreatedAt = S::CreatedAt;
type Topic = Set<members::topic>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct purpose(());
pub struct name(());
pub struct created_at(());
pub struct topic(());
}
}
pub struct RoomBuilder<'a, S: room_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<RoomPurpose<'a>>,
Option<room::RoomSettings<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Room<'a> {
pub fn new() -> RoomBuilder<'a, room_state::Empty> {
RoomBuilder::new()
}
}
impl<'a> RoomBuilder<'a, room_state::Empty> {
pub fn new() -> Self {
RoomBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: room_state::State> RoomBuilder<'a, S> {
pub fn category(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_category(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> RoomBuilder<'a, S>
where
S: room_state::State,
S::CreatedAt: room_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> RoomBuilder<'a, room_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
RoomBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: room_state::State> RoomBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> RoomBuilder<'a, S>
where
S: room_state::State,
S::Name: room_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> RoomBuilder<'a, room_state::SetName<S>> {
self._fields.3 = Option::Some(value.into());
RoomBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RoomBuilder<'a, S>
where
S: room_state::State,
S::Purpose: room_state::IsUnset,
{
pub fn purpose(
mut self,
value: impl Into<RoomPurpose<'a>>,
) -> RoomBuilder<'a, room_state::SetPurpose<S>> {
self._fields.4 = Option::Some(value.into());
RoomBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: room_state::State> RoomBuilder<'a, S> {
pub fn settings(mut self, value: impl Into<Option<room::RoomSettings<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_settings(mut self, value: Option<room::RoomSettings<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S> RoomBuilder<'a, S>
where
S: room_state::State,
S::Topic: room_state::IsUnset,
{
pub fn topic(
mut self,
value: impl Into<CowStr<'a>>,
) -> RoomBuilder<'a, room_state::SetTopic<S>> {
self._fields.6 = Option::Some(value.into());
RoomBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RoomBuilder<'a, S>
where
S: room_state::State,
S::Purpose: room_state::IsSet,
S::Name: room_state::IsSet,
S::CreatedAt: room_state::IsSet,
S::Topic: room_state::IsSet,
{
pub fn build(self) -> Room<'a> {
Room {
category: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
name: self._fields.3.unwrap(),
purpose: self._fields.4.unwrap(),
settings: self._fields.5,
topic: self._fields.6.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>,
>,
) -> Room<'a> {
Room {
category: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
name: self._fields.3.unwrap(),
purpose: self._fields.4.unwrap(),
settings: self._fields.5,
topic: self._fields.6.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_protoimsg_chat_room() -> 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.room"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Declares a chat room. Created by whoever starts the room.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"), SmolStr::new_static("topic"),
SmolStr::new_static("purpose"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("category"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Broad category for room discovery (e.g., music, tech, gaming). Lowercased.",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Timestamp of room creation."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("What the room is about."),
),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Display name for the room."),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("purpose"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Room purpose categorization."),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("settings"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#roomSettings"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("topic"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Room topic for sorting, filtering, and discovery.",
),
),
max_length: Some(200usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("roomSettings"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static("Configurable room settings.")),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("allowlistEnabled"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("minAccountAgeDays"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("slowModeSeconds"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("visibility"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Room discoverability. public = listed in directory, unlisted = link only, private = invite only.",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
fn _default_room_settings_allowlist_enabled() -> Option<bool> {
Some(false)
}
fn _default_room_settings_min_account_age_days() -> Option<i64> {
Some(0i64)
}
fn _default_room_settings_slow_mode_seconds() -> Option<i64> {
Some(0i64)
}
impl Default for RoomSettings<'_> {
fn default() -> Self {
Self {
allowlist_enabled: Some(false),
min_account_age_days: Some(0i64),
slow_mode_seconds: Some(0i64),
visibility: None,
extra_data: Default::default(),
}
}
}