#[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::{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};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", rename = "com.5jiji.test.videos", tag = "$type")]
pub struct Videos<'a> {
#[serde(borrow)]
pub creator: Did<'a>,
#[serde(borrow)]
pub id: Data<'a>,
#[serde(borrow)]
pub title: CowStr<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct VideosGetRecordOutput<'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: Videos<'a>,
}
impl<'a> Videos<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, VideosRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[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<'de> = VideosGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<VideosGetRecordOutput<'_>> for Videos<'_> {
fn from(output: VideosGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Videos<'_> {
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<'a> LexiconSchema for Videos<'a> {
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 Creator;
type Title;
type Id;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Creator = Unset;
type Title = Unset;
type Id = Unset;
}
pub struct SetCreator<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreator<S> {}
impl<S: State> State for SetCreator<S> {
type Creator = Set<members::creator>;
type Title = S::Title;
type Id = S::Id;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type Creator = S::Creator;
type Title = Set<members::title>;
type Id = S::Id;
}
pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetId<S> {}
impl<S: State> State for SetId<S> {
type Creator = S::Creator;
type Title = S::Title;
type Id = Set<members::id>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct creator(());
pub struct title(());
pub struct id(());
}
}
pub struct VideosBuilder<'a, S: videos_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Did<'a>>, Option<Data<'a>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Videos<'a> {
pub fn new() -> VideosBuilder<'a, videos_state::Empty> {
VideosBuilder::new()
}
}
impl<'a> VideosBuilder<'a, videos_state::Empty> {
pub fn new() -> Self {
VideosBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> VideosBuilder<'a, S>
where
S: videos_state::State,
S::Creator: videos_state::IsUnset,
{
pub fn creator(
mut self,
value: impl Into<Did<'a>>,
) -> VideosBuilder<'a, videos_state::SetCreator<S>> {
self._fields.0 = Option::Some(value.into());
VideosBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> VideosBuilder<'a, S>
where
S: videos_state::State,
S::Id: videos_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<Data<'a>>,
) -> VideosBuilder<'a, videos_state::SetId<S>> {
self._fields.1 = Option::Some(value.into());
VideosBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> VideosBuilder<'a, S>
where
S: videos_state::State,
S::Title: videos_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> VideosBuilder<'a, videos_state::SetTitle<S>> {
self._fields.2 = Option::Some(value.into());
VideosBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> VideosBuilder<'a, S>
where
S: videos_state::State,
S::Creator: videos_state::IsSet,
S::Title: videos_state::IsSet,
S::Id: videos_state::IsSet,
{
pub fn build(self) -> Videos<'a> {
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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Videos<'a> {
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()
}
}