#[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::{AtUri, Cid};
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::com_atproto::repo::strong_ref::StrongRef;
use crate::app_chavatar::settings;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct AvatarItem<S: BosStr = DefaultStr> {
pub id: S,
pub image: StrongRef<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.chavatar.settings",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Settings<S: BosStr = DefaultStr> {
pub avatars: Vec<settings::AvatarItem<S>>,
pub enabled: bool,
pub interval: SettingsInterval<S>,
pub mode: SettingsMode<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SettingsInterval<S: BosStr = DefaultStr> {
_1h,
_3h,
_6h,
_12h,
_1d,
_1w,
_1mo,
Other(S),
}
impl<S: BosStr> SettingsInterval<S> {
pub fn as_str(&self) -> &str {
match self {
Self::_1h => "1h",
Self::_3h => "3h",
Self::_6h => "6h",
Self::_12h => "12h",
Self::_1d => "1d",
Self::_1w => "1w",
Self::_1mo => "1mo",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"1h" => Self::_1h,
"3h" => Self::_3h,
"6h" => Self::_6h,
"12h" => Self::_12h,
"1d" => Self::_1d,
"1w" => Self::_1w,
"1mo" => Self::_1mo,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for SettingsInterval<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for SettingsInterval<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for SettingsInterval<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for SettingsInterval<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for SettingsInterval<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for SettingsInterval<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = SettingsInterval<S::Output>;
fn into_static(self) -> Self::Output {
match self {
SettingsInterval::_1h => SettingsInterval::_1h,
SettingsInterval::_3h => SettingsInterval::_3h,
SettingsInterval::_6h => SettingsInterval::_6h,
SettingsInterval::_12h => SettingsInterval::_12h,
SettingsInterval::_1d => SettingsInterval::_1d,
SettingsInterval::_1w => SettingsInterval::_1w,
SettingsInterval::_1mo => SettingsInterval::_1mo,
SettingsInterval::Other(v) => SettingsInterval::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SettingsMode<S: BosStr = DefaultStr> {
Sequential,
Random,
Other(S),
}
impl<S: BosStr> SettingsMode<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Sequential => "sequential",
Self::Random => "random",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"sequential" => Self::Sequential,
"random" => Self::Random,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for SettingsMode<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for SettingsMode<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for SettingsMode<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for SettingsMode<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for SettingsMode<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for SettingsMode<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = SettingsMode<S::Output>;
fn into_static(self) -> Self::Output {
match self {
SettingsMode::Sequential => SettingsMode::Sequential,
SettingsMode::Random => SettingsMode::Random,
SettingsMode::Other(v) => SettingsMode::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SettingsGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Settings<S>,
}
impl<S: BosStr> Settings<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, SettingsRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for AvatarItem<S> {
fn nsid() -> &'static str {
"app.chavatar.settings"
}
fn def_name() -> &'static str {
"avatarItem"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_chavatar_settings()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 13usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("id"),
max: 13usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SettingsRecord;
impl XrpcResp for SettingsRecord {
const NSID: &'static str = "app.chavatar.settings";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = SettingsGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<SettingsGetRecordOutput<S>> for Settings<S> {
fn from(output: SettingsGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Settings<S> {
const NSID: &'static str = "app.chavatar.settings";
type Record = SettingsRecord;
}
impl Collection for SettingsRecord {
const NSID: &'static str = "app.chavatar.settings";
type Record = SettingsRecord;
}
impl<S: BosStr> LexiconSchema for Settings<S> {
fn nsid() -> &'static str {
"app.chavatar.settings"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_chavatar_settings()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.interval;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("interval"),
max: 10usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.mode;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("mode"),
max: 20usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod avatar_item_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 Image;
type Id;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Image = Unset;
type Id = Unset;
}
pub struct SetImage<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetImage<St> {}
impl<St: State> State for SetImage<St> {
type Image = Set<members::image>;
type Id = St::Id;
}
pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetId<St> {}
impl<St: State> State for SetId<St> {
type Image = St::Image;
type Id = Set<members::id>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct image(());
pub struct id(());
}
}
pub struct AvatarItemBuilder<S: BosStr, St: avatar_item_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<StrongRef<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> AvatarItem<S> {
pub fn new() -> AvatarItemBuilder<S, avatar_item_state::Empty> {
AvatarItemBuilder::new()
}
}
impl<S: BosStr> AvatarItemBuilder<S, avatar_item_state::Empty> {
pub fn new() -> Self {
AvatarItemBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AvatarItemBuilder<S, St>
where
St: avatar_item_state::State,
St::Id: avatar_item_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<S>,
) -> AvatarItemBuilder<S, avatar_item_state::SetId<St>> {
self._fields.0 = Option::Some(value.into());
AvatarItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AvatarItemBuilder<S, St>
where
St: avatar_item_state::State,
St::Image: avatar_item_state::IsUnset,
{
pub fn image(
mut self,
value: impl Into<StrongRef<S>>,
) -> AvatarItemBuilder<S, avatar_item_state::SetImage<St>> {
self._fields.1 = Option::Some(value.into());
AvatarItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AvatarItemBuilder<S, St>
where
St: avatar_item_state::State,
St::Image: avatar_item_state::IsSet,
St::Id: avatar_item_state::IsSet,
{
pub fn build(self) -> AvatarItem<S> {
AvatarItem {
id: self._fields.0.unwrap(),
image: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> AvatarItem<S> {
AvatarItem {
id: self._fields.0.unwrap(),
image: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_chavatar_settings() -> 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.chavatar.settings"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("avatarItem"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("id"), SmolStr::new_static("image")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("id"),
LexObjectProperty::String(LexString {
max_length: Some(13usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("image"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("Rotation configuration for a user."),
),
key: Some(CowStr::new_static("literal:self")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("enabled"),
SmolStr::new_static("interval"),
SmolStr::new_static("mode"), SmolStr::new_static("avatars")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("avatars"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#avatarItem"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("enabled"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("interval"),
LexObjectProperty::String(LexString {
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("mode"),
LexObjectProperty::String(LexString {
max_length: Some(20usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod settings_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 Avatars;
type Enabled;
type Interval;
type Mode;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Avatars = Unset;
type Enabled = Unset;
type Interval = Unset;
type Mode = Unset;
}
pub struct SetAvatars<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAvatars<St> {}
impl<St: State> State for SetAvatars<St> {
type Avatars = Set<members::avatars>;
type Enabled = St::Enabled;
type Interval = St::Interval;
type Mode = St::Mode;
}
pub struct SetEnabled<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEnabled<St> {}
impl<St: State> State for SetEnabled<St> {
type Avatars = St::Avatars;
type Enabled = Set<members::enabled>;
type Interval = St::Interval;
type Mode = St::Mode;
}
pub struct SetInterval<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetInterval<St> {}
impl<St: State> State for SetInterval<St> {
type Avatars = St::Avatars;
type Enabled = St::Enabled;
type Interval = Set<members::interval>;
type Mode = St::Mode;
}
pub struct SetMode<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMode<St> {}
impl<St: State> State for SetMode<St> {
type Avatars = St::Avatars;
type Enabled = St::Enabled;
type Interval = St::Interval;
type Mode = Set<members::mode>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct avatars(());
pub struct enabled(());
pub struct interval(());
pub struct mode(());
}
}
pub struct SettingsBuilder<S: BosStr, St: settings_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<settings::AvatarItem<S>>>,
Option<bool>,
Option<SettingsInterval<S>>,
Option<SettingsMode<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Settings<S> {
pub fn new() -> SettingsBuilder<S, settings_state::Empty> {
SettingsBuilder::new()
}
}
impl<S: BosStr> SettingsBuilder<S, settings_state::Empty> {
pub fn new() -> Self {
SettingsBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SettingsBuilder<S, St>
where
St: settings_state::State,
St::Avatars: settings_state::IsUnset,
{
pub fn avatars(
mut self,
value: impl Into<Vec<settings::AvatarItem<S>>>,
) -> SettingsBuilder<S, settings_state::SetAvatars<St>> {
self._fields.0 = Option::Some(value.into());
SettingsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SettingsBuilder<S, St>
where
St: settings_state::State,
St::Enabled: settings_state::IsUnset,
{
pub fn enabled(
mut self,
value: impl Into<bool>,
) -> SettingsBuilder<S, settings_state::SetEnabled<St>> {
self._fields.1 = Option::Some(value.into());
SettingsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SettingsBuilder<S, St>
where
St: settings_state::State,
St::Interval: settings_state::IsUnset,
{
pub fn interval(
mut self,
value: impl Into<SettingsInterval<S>>,
) -> SettingsBuilder<S, settings_state::SetInterval<St>> {
self._fields.2 = Option::Some(value.into());
SettingsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SettingsBuilder<S, St>
where
St: settings_state::State,
St::Mode: settings_state::IsUnset,
{
pub fn mode(
mut self,
value: impl Into<SettingsMode<S>>,
) -> SettingsBuilder<S, settings_state::SetMode<St>> {
self._fields.3 = Option::Some(value.into());
SettingsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SettingsBuilder<S, St>
where
St: settings_state::State,
St::Avatars: settings_state::IsSet,
St::Enabled: settings_state::IsSet,
St::Interval: settings_state::IsSet,
St::Mode: settings_state::IsSet,
{
pub fn build(self) -> Settings<S> {
Settings {
avatars: self._fields.0.unwrap(),
enabled: self._fields.1.unwrap(),
interval: self._fields.2.unwrap(),
mode: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Settings<S> {
Settings {
avatars: self._fields.0.unwrap(),
enabled: self._fields.1.unwrap(),
interval: self._fields.2.unwrap(),
mode: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}