#[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, Datetime};
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::scot_comhairle::testing_polis_statement_v1;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "scot.comhairle.testingPolisStatementV1",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct TestingPolisStatementV1<S: BosStr = DefaultStr> {
pub created_at: Datetime,
pub poll: testing_polis_statement_v1::PollRef<S>,
pub text: 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 TestingPolisStatementV1GetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: TestingPolisStatementV1<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PollRef<S: BosStr = DefaultStr> {
pub cid: Cid<S>,
pub uri: AtUri<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> TestingPolisStatementV1<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, TestingPolisStatementV1Record>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TestingPolisStatementV1Record;
impl XrpcResp for TestingPolisStatementV1Record {
const NSID: &'static str = "scot.comhairle.testingPolisStatementV1";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = TestingPolisStatementV1GetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<TestingPolisStatementV1GetRecordOutput<S>>
for TestingPolisStatementV1<S> {
fn from(output: TestingPolisStatementV1GetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for TestingPolisStatementV1<S> {
const NSID: &'static str = "scot.comhairle.testingPolisStatementV1";
type Record = TestingPolisStatementV1Record;
}
impl Collection for TestingPolisStatementV1Record {
const NSID: &'static str = "scot.comhairle.testingPolisStatementV1";
type Record = TestingPolisStatementV1Record;
}
impl<S: BosStr> LexiconSchema for TestingPolisStatementV1<S> {
fn nsid() -> &'static str {
"scot.comhairle.testingPolisStatementV1"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_scot_comhairle_testingPolisStatementV1()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.text;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("text"),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for PollRef<S> {
fn nsid() -> &'static str {
"scot.comhairle.testingPolisStatementV1"
}
fn def_name() -> &'static str {
"pollRef"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_scot_comhairle_testingPolisStatementV1()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod testing_polis_statement_v1_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 CreatedAt;
type Poll;
type Text;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Poll = Unset;
type Text = 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 Poll = St::Poll;
type Text = St::Text;
}
pub struct SetPoll<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPoll<St> {}
impl<St: State> State for SetPoll<St> {
type CreatedAt = St::CreatedAt;
type Poll = Set<members::poll>;
type Text = St::Text;
}
pub struct SetText<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetText<St> {}
impl<St: State> State for SetText<St> {
type CreatedAt = St::CreatedAt;
type Poll = St::Poll;
type Text = Set<members::text>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct poll(());
pub struct text(());
}
}
pub struct TestingPolisStatementV1Builder<
S: BosStr,
St: testing_polis_statement_v1_state::State,
> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<testing_polis_statement_v1::PollRef<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> TestingPolisStatementV1<S> {
pub fn new() -> TestingPolisStatementV1Builder<
S,
testing_polis_statement_v1_state::Empty,
> {
TestingPolisStatementV1Builder::new()
}
}
impl<
S: BosStr,
> TestingPolisStatementV1Builder<S, testing_polis_statement_v1_state::Empty> {
pub fn new() -> Self {
TestingPolisStatementV1Builder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> TestingPolisStatementV1Builder<S, St>
where
St: testing_polis_statement_v1_state::State,
St::CreatedAt: testing_polis_statement_v1_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> TestingPolisStatementV1Builder<
S,
testing_polis_statement_v1_state::SetCreatedAt<St>,
> {
self._fields.0 = Option::Some(value.into());
TestingPolisStatementV1Builder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> TestingPolisStatementV1Builder<S, St>
where
St: testing_polis_statement_v1_state::State,
St::Poll: testing_polis_statement_v1_state::IsUnset,
{
pub fn poll(
mut self,
value: impl Into<testing_polis_statement_v1::PollRef<S>>,
) -> TestingPolisStatementV1Builder<
S,
testing_polis_statement_v1_state::SetPoll<St>,
> {
self._fields.1 = Option::Some(value.into());
TestingPolisStatementV1Builder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> TestingPolisStatementV1Builder<S, St>
where
St: testing_polis_statement_v1_state::State,
St::Text: testing_polis_statement_v1_state::IsUnset,
{
pub fn text(
mut self,
value: impl Into<S>,
) -> TestingPolisStatementV1Builder<
S,
testing_polis_statement_v1_state::SetText<St>,
> {
self._fields.2 = Option::Some(value.into());
TestingPolisStatementV1Builder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> TestingPolisStatementV1Builder<S, St>
where
St: testing_polis_statement_v1_state::State,
St::CreatedAt: testing_polis_statement_v1_state::IsSet,
St::Poll: testing_polis_statement_v1_state::IsSet,
St::Text: testing_polis_statement_v1_state::IsSet,
{
pub fn build(self) -> TestingPolisStatementV1<S> {
TestingPolisStatementV1 {
created_at: self._fields.0.unwrap(),
poll: self._fields.1.unwrap(),
text: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> TestingPolisStatementV1<S> {
TestingPolisStatementV1 {
created_at: self._fields.0.unwrap(),
poll: self._fields.1.unwrap(),
text: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_scot_comhairle_testingPolisStatementV1() -> 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("scot.comhairle.testingPolisStatementV1"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A statement in the Polis-style deliberation system",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("text"), SmolStr::new_static("poll"),
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(
"Timestamp when the statement was created",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("poll"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#pollRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("text"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The text content of the statement"),
),
max_length: Some(3000usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("pollRef"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static("Reference to a poll record")),
required: Some(
vec![SmolStr::new_static("uri"), SmolStr::new_static("cid")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("cid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Content identifier of the poll record"),
),
format: Some(LexStringFormat::Cid),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("AT-URI of the poll record"),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod poll_ref_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 Cid;
type Uri;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Cid = Unset;
type Uri = Unset;
}
pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCid<St> {}
impl<St: State> State for SetCid<St> {
type Cid = Set<members::cid>;
type Uri = St::Uri;
}
pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUri<St> {}
impl<St: State> State for SetUri<St> {
type Cid = St::Cid;
type Uri = Set<members::uri>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct cid(());
pub struct uri(());
}
}
pub struct PollRefBuilder<S: BosStr, St: poll_ref_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Cid<S>>, Option<AtUri<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> PollRef<S> {
pub fn new() -> PollRefBuilder<S, poll_ref_state::Empty> {
PollRefBuilder::new()
}
}
impl<S: BosStr> PollRefBuilder<S, poll_ref_state::Empty> {
pub fn new() -> Self {
PollRefBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PollRefBuilder<S, St>
where
St: poll_ref_state::State,
St::Cid: poll_ref_state::IsUnset,
{
pub fn cid(
mut self,
value: impl Into<Cid<S>>,
) -> PollRefBuilder<S, poll_ref_state::SetCid<St>> {
self._fields.0 = Option::Some(value.into());
PollRefBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PollRefBuilder<S, St>
where
St: poll_ref_state::State,
St::Uri: poll_ref_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<S>>,
) -> PollRefBuilder<S, poll_ref_state::SetUri<St>> {
self._fields.1 = Option::Some(value.into());
PollRefBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PollRefBuilder<S, St>
where
St: poll_ref_state::State,
St::Cid: poll_ref_state::IsSet,
St::Uri: poll_ref_state::IsSet,
{
pub fn build(self) -> PollRef<S> {
PollRef {
cid: self._fields.0.unwrap(),
uri: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> PollRef<S> {
PollRef {
cid: self._fields.0.unwrap(),
uri: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}