#[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::string::{AtUri, Cid, Datetime, Language};
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;
use crate::community_lexicon::app::Image;
use crate::community_lexicon::app::Link;
#[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 = "community.lexicon.app.profileLocalization",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ProfileLocalization<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub images: Option<Vec<Image<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<Vec<Link<S>>>,
pub locale: Language,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<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 ProfileLocalizationGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: ProfileLocalization<S>,
}
impl<S: BosStr> ProfileLocalization<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ProfileLocalizationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProfileLocalizationRecord;
impl XrpcResp for ProfileLocalizationRecord {
const NSID: &'static str = "community.lexicon.app.profileLocalization";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ProfileLocalizationGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ProfileLocalizationGetRecordOutput<S>> for ProfileLocalization<S> {
fn from(output: ProfileLocalizationGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for ProfileLocalization<S> {
const NSID: &'static str = "community.lexicon.app.profileLocalization";
type Record = ProfileLocalizationRecord;
}
impl Collection for ProfileLocalizationRecord {
const NSID: &'static str = "community.lexicon.app.profileLocalization";
type Record = ProfileLocalizationRecord;
}
impl<S: BosStr> LexiconSchema for ProfileLocalization<S> {
fn nsid() -> &'static str {
"community.lexicon.app.profileLocalization"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_community_lexicon_app_profileLocalization()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 300usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("description"),
max: 300usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.images {
#[allow(unused_comparisons)]
if value.len() > 24usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("images"),
max: 24usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.links {
#[allow(unused_comparisons)]
if value.len() > 12usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("links"),
max: 12usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.links {
#[allow(unused_comparisons)]
if value.len() < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("links"),
min: 1usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 200usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.name {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 100usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("name"),
max: 100usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.tags {
#[allow(unused_comparisons)]
if value.len() > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 10usize,
actual: value.len(),
});
}
}
Ok(())
}
}
pub mod profile_localization_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 Locale;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Locale = 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 Locale = St::Locale;
}
pub struct SetLocale<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLocale<St> {}
impl<St: State> State for SetLocale<St> {
type CreatedAt = St::CreatedAt;
type Locale = Set<members::locale>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct locale(());
}
}
pub struct ProfileLocalizationBuilder<St: profile_localization_state::State, S: BosStr = DefaultStr>
{
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<Vec<Image<S>>>,
Option<Vec<Link<S>>>,
Option<Language>,
Option<S>,
Option<Vec<S>>,
Option<Datetime>,
),
_type: PhantomData<fn() -> S>,
}
impl ProfileLocalization<DefaultStr> {
pub fn new() -> ProfileLocalizationBuilder<profile_localization_state::Empty, DefaultStr> {
ProfileLocalizationBuilder::new()
}
}
impl<S: BosStr> ProfileLocalization<S> {
pub fn builder() -> ProfileLocalizationBuilder<profile_localization_state::Empty, S> {
ProfileLocalizationBuilder::builder()
}
}
impl ProfileLocalizationBuilder<profile_localization_state::Empty, DefaultStr> {
pub fn new() -> Self {
ProfileLocalizationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> ProfileLocalizationBuilder<profile_localization_state::Empty, S> {
pub fn builder() -> Self {
ProfileLocalizationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ProfileLocalizationBuilder<St, S>
where
St: profile_localization_state::State,
St::CreatedAt: profile_localization_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ProfileLocalizationBuilder<profile_localization_state::SetCreatedAt<St>, S> {
self._fields.0 = Option::Some(value.into());
ProfileLocalizationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: profile_localization_state::State, S: BosStr> ProfileLocalizationBuilder<St, S> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<St: profile_localization_state::State, S: BosStr> ProfileLocalizationBuilder<St, S> {
pub fn images(mut self, value: impl Into<Option<Vec<Image<S>>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_images(mut self, value: Option<Vec<Image<S>>>) -> Self {
self._fields.2 = value;
self
}
}
impl<St: profile_localization_state::State, S: BosStr> ProfileLocalizationBuilder<St, S> {
pub fn links(mut self, value: impl Into<Option<Vec<Link<S>>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_links(mut self, value: Option<Vec<Link<S>>>) -> Self {
self._fields.3 = value;
self
}
}
impl<St, S: BosStr> ProfileLocalizationBuilder<St, S>
where
St: profile_localization_state::State,
St::Locale: profile_localization_state::IsUnset,
{
pub fn locale(
mut self,
value: impl Into<Language>,
) -> ProfileLocalizationBuilder<profile_localization_state::SetLocale<St>, S> {
self._fields.4 = Option::Some(value.into());
ProfileLocalizationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: profile_localization_state::State, S: BosStr> ProfileLocalizationBuilder<St, S> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<St: profile_localization_state::State, S: BosStr> ProfileLocalizationBuilder<St, S> {
pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
self._fields.6 = value;
self
}
}
impl<St: profile_localization_state::State, S: BosStr> ProfileLocalizationBuilder<St, S> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.7 = value;
self
}
}
impl<St, S: BosStr> ProfileLocalizationBuilder<St, S>
where
St: profile_localization_state::State,
St::CreatedAt: profile_localization_state::IsSet,
St::Locale: profile_localization_state::IsSet,
{
pub fn build(self) -> ProfileLocalization<S> {
ProfileLocalization {
created_at: self._fields.0.unwrap(),
description: self._fields.1,
images: self._fields.2,
links: self._fields.3,
locale: self._fields.4.unwrap(),
name: self._fields.5,
tags: self._fields.6,
updated_at: self._fields.7,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ProfileLocalization<S> {
ProfileLocalization {
created_at: self._fields.0.unwrap(),
description: self._fields.1,
images: self._fields.2,
links: self._fields.3,
locale: self._fields.4.unwrap(),
name: self._fields.5,
tags: self._fields.6,
updated_at: self._fields.7,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_community_lexicon_app_profileLocalization() -> 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("community.lexicon.app.profileLocalization"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A locale-specific override for an app profile. This record should be published by the same DID as the canonical app profile.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("locale"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this localization was created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Localized description of what the app does.",
),
),
max_length: Some(3000usize),
max_graphemes: Some(300usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("images"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Localized visual assets for directories and stores, such as icons, hero images, screenshots, banners, and social cards.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#image",
),
..Default::default()
}),
max_length: Some(24usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("links"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Localized destinations for the app. The first link should be the primary destination for this locale.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#link",
),
..Default::default()
}),
min_length: Some(1usize),
max_length: Some(12usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("locale"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"BCP 47 language tag for this localized metadata.",
),
),
format: Some(LexStringFormat::Language),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Localized display name of the app."),
),
max_length: Some(200usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Localized discovery tags for filtering and search.",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(64usize),
max_graphemes: Some(32usize),
..Default::default()
}),
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this localization was last updated.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}