#[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};
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};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "com.5jiji.test.videos",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Videos<S: BosStr = DefaultStr> {
pub creator: Did<S>,
pub id: Data<S>,
pub title: 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 VideosGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Videos<S>,
}
impl<S: BosStr> Videos<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, VideosRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VideosRecord;
impl XrpcResp for VideosRecord {
const NSID: &'static str = "com.5jiji.test.videos";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = VideosGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<VideosGetRecordOutput<S>> for Videos<S> {
fn from(output: VideosGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Videos<S> {
const NSID: &'static str = "com.5jiji.test.videos";
type Record = VideosRecord;
}
impl Collection for VideosRecord {
const NSID: &'static str = "com.5jiji.test.videos";
type Record = VideosRecord;
}
impl<S: BosStr> LexiconSchema for Videos<S> {
fn nsid() -> &'static str {
"com.5jiji.test.videos"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_com_5jiji_test_videos()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.title;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 150usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 150usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod videos_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 Id;
type Creator;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Id = Unset;
type Creator = Unset;
type Title = Unset;
}
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 Id = Set<members::id>;
type Creator = St::Creator;
type Title = St::Title;
}
pub struct SetCreator<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreator<St> {}
impl<St: State> State for SetCreator<St> {
type Id = St::Id;
type Creator = Set<members::creator>;
type Title = St::Title;
}
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 Id = St::Id;
type Creator = St::Creator;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct id(());
pub struct creator(());
pub struct title(());
}
}
pub struct VideosBuilder<S: BosStr, St: videos_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Did<S>>, Option<Data<S>>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Videos<S> {
pub fn new() -> VideosBuilder<S, videos_state::Empty> {
VideosBuilder::new()
}
}
impl<S: BosStr> VideosBuilder<S, videos_state::Empty> {
pub fn new() -> Self {
VideosBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> VideosBuilder<S, St>
where
St: videos_state::State,
St::Creator: videos_state::IsUnset,
{
pub fn creator(
mut self,
value: impl Into<Did<S>>,
) -> VideosBuilder<S, videos_state::SetCreator<St>> {
self._fields.0 = Option::Some(value.into());
VideosBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> VideosBuilder<S, St>
where
St: videos_state::State,
St::Id: videos_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<Data<S>>,
) -> VideosBuilder<S, videos_state::SetId<St>> {
self._fields.1 = Option::Some(value.into());
VideosBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> VideosBuilder<S, St>
where
St: videos_state::State,
St::Title: videos_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> VideosBuilder<S, videos_state::SetTitle<St>> {
self._fields.2 = Option::Some(value.into());
VideosBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> VideosBuilder<S, St>
where
St: videos_state::State,
St::Id: videos_state::IsSet,
St::Creator: videos_state::IsSet,
St::Title: videos_state::IsSet,
{
pub fn build(self) -> Videos<S> {
Videos {
creator: self._fields.0.unwrap(),
id: self._fields.1.unwrap(),
title: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Videos<S> {
Videos {
creator: self._fields.0.unwrap(),
id: self._fields.1.unwrap(),
title: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_com_5jiji_test_videos() -> 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("com.5jiji.test.videos"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("A video")),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("id"), SmolStr::new_static("title"),
SmolStr::new_static("creator")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("creator"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("id"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.5jiji.test.vidId"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
max_graphemes: Some(150usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}