#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::deps::bytes::Bytes;
#[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, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
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")]
pub struct Proposal<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub aid: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
pub cts: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub note: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub reasons: Option<Vec<CowStr<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, with = "jacquard_common::opt_serde_bytes_helper")]
pub sig: Option<Bytes>,
#[serde(borrow)]
pub src: Did<'a>,
#[serde(borrow)]
pub typ: CowStr<'a>,
#[serde(borrow)]
pub uri: UriValue<'a>,
#[serde(borrow)]
pub val: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ver: Option<i64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ProposalGetRecordOutput<'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: Proposal<'a>,
}
impl<'a> Proposal<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, ProposalRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProposalRecord;
impl XrpcResp for ProposalRecord {
const NSID: &'static str = "social.pmsky.proposal";
const ENCODING: &'static str = "application/json";
type Output<'de> = ProposalGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<ProposalGetRecordOutput<'_>> for Proposal<'_> {
fn from(output: ProposalGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Proposal<'_> {
const NSID: &'static str = "social.pmsky.proposal";
type Record = ProposalRecord;
}
impl Collection for ProposalRecord {
const NSID: &'static str = "social.pmsky.proposal";
type Record = ProposalRecord;
}
impl<'a> LexiconSchema for Proposal<'a> {
fn nsid() -> &'static str {
"social.pmsky.proposal"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_social_pmsky_proposal()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.val;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("val"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod proposal_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 Uri;
type Val;
type Typ;
type Src;
type Cts;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Uri = Unset;
type Val = Unset;
type Typ = Unset;
type Src = Unset;
type Cts = Unset;
}
pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUri<S> {}
impl<S: State> State for SetUri<S> {
type Uri = Set<members::uri>;
type Val = S::Val;
type Typ = S::Typ;
type Src = S::Src;
type Cts = S::Cts;
}
pub struct SetVal<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetVal<S> {}
impl<S: State> State for SetVal<S> {
type Uri = S::Uri;
type Val = Set<members::val>;
type Typ = S::Typ;
type Src = S::Src;
type Cts = S::Cts;
}
pub struct SetTyp<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTyp<S> {}
impl<S: State> State for SetTyp<S> {
type Uri = S::Uri;
type Val = S::Val;
type Typ = Set<members::typ>;
type Src = S::Src;
type Cts = S::Cts;
}
pub struct SetSrc<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSrc<S> {}
impl<S: State> State for SetSrc<S> {
type Uri = S::Uri;
type Val = S::Val;
type Typ = S::Typ;
type Src = Set<members::src>;
type Cts = S::Cts;
}
pub struct SetCts<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCts<S> {}
impl<S: State> State for SetCts<S> {
type Uri = S::Uri;
type Val = S::Val;
type Typ = S::Typ;
type Src = S::Src;
type Cts = Set<members::cts>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct uri(());
pub struct val(());
pub struct typ(());
pub struct src(());
pub struct cts(());
}
}
pub struct ProposalBuilder<'a, S: proposal_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Cid<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<Vec<CowStr<'a>>>,
Option<Bytes>,
Option<Did<'a>>,
Option<CowStr<'a>>,
Option<UriValue<'a>>,
Option<CowStr<'a>>,
Option<i64>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Proposal<'a> {
pub fn new() -> ProposalBuilder<'a, proposal_state::Empty> {
ProposalBuilder::new()
}
}
impl<'a> ProposalBuilder<'a, proposal_state::Empty> {
pub fn new() -> Self {
ProposalBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: proposal_state::State> ProposalBuilder<'a, S> {
pub fn aid(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_aid(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: proposal_state::State> ProposalBuilder<'a, S> {
pub fn cid(mut self, value: impl Into<Option<Cid<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_cid(mut self, value: Option<Cid<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> ProposalBuilder<'a, S>
where
S: proposal_state::State,
S::Cts: proposal_state::IsUnset,
{
pub fn cts(
mut self,
value: impl Into<Datetime>,
) -> ProposalBuilder<'a, proposal_state::SetCts<S>> {
self._fields.2 = Option::Some(value.into());
ProposalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: proposal_state::State> ProposalBuilder<'a, S> {
pub fn note(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_note(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: proposal_state::State> ProposalBuilder<'a, S> {
pub fn reasons(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_reasons(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: proposal_state::State> ProposalBuilder<'a, S> {
pub fn sig(mut self, value: impl Into<Option<Bytes>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_sig(mut self, value: Option<Bytes>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S> ProposalBuilder<'a, S>
where
S: proposal_state::State,
S::Src: proposal_state::IsUnset,
{
pub fn src(
mut self,
value: impl Into<Did<'a>>,
) -> ProposalBuilder<'a, proposal_state::SetSrc<S>> {
self._fields.6 = Option::Some(value.into());
ProposalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ProposalBuilder<'a, S>
where
S: proposal_state::State,
S::Typ: proposal_state::IsUnset,
{
pub fn typ(
mut self,
value: impl Into<CowStr<'a>>,
) -> ProposalBuilder<'a, proposal_state::SetTyp<S>> {
self._fields.7 = Option::Some(value.into());
ProposalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ProposalBuilder<'a, S>
where
S: proposal_state::State,
S::Uri: proposal_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<UriValue<'a>>,
) -> ProposalBuilder<'a, proposal_state::SetUri<S>> {
self._fields.8 = Option::Some(value.into());
ProposalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ProposalBuilder<'a, S>
where
S: proposal_state::State,
S::Val: proposal_state::IsUnset,
{
pub fn val(
mut self,
value: impl Into<CowStr<'a>>,
) -> ProposalBuilder<'a, proposal_state::SetVal<S>> {
self._fields.9 = Option::Some(value.into());
ProposalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: proposal_state::State> ProposalBuilder<'a, S> {
pub fn ver(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_ver(mut self, value: Option<i64>) -> Self {
self._fields.10 = value;
self
}
}
impl<'a, S> ProposalBuilder<'a, S>
where
S: proposal_state::State,
S::Uri: proposal_state::IsSet,
S::Val: proposal_state::IsSet,
S::Typ: proposal_state::IsSet,
S::Src: proposal_state::IsSet,
S::Cts: proposal_state::IsSet,
{
pub fn build(self) -> Proposal<'a> {
Proposal {
aid: self._fields.0,
cid: self._fields.1,
cts: self._fields.2.unwrap(),
note: self._fields.3,
reasons: self._fields.4,
sig: self._fields.5,
src: self._fields.6.unwrap(),
typ: self._fields.7.unwrap(),
uri: self._fields.8.unwrap(),
val: self._fields.9.unwrap(),
ver: self._fields.10,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Proposal<'a> {
Proposal {
aid: self._fields.0,
cid: self._fields.1,
cts: self._fields.2.unwrap(),
note: self._fields.3,
reasons: self._fields.4,
sig: self._fields.5,
src: self._fields.6.unwrap(),
typ: self._fields.7.unwrap(),
uri: self._fields.8.unwrap(),
val: self._fields.9.unwrap(),
ver: self._fields.10,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_social_pmsky_proposal() -> 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("social.pmsky.proposal"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
description: Some(
CowStr::new_static(
"A proposed moderation action (e.g. adding a label or annotation to a post). Refers to some other resource via URI (e.g. an atproto post). Superset of 'com.atproto.proposal.defs#label.",
),
),
required: Some(
vec![
SmolStr::new_static("typ"), SmolStr::new_static("src"),
SmolStr::new_static("uri"), SmolStr::new_static("val"),
SmolStr::new_static("cts")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("aid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The persistent, anonymous identifier for the user creating the proposal.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("cid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optionally, CID specifying the specific version of 'uri' resource this proposal applies to.",
),
),
format: Some(LexStringFormat::Cid),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("cts"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when this proposal was created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("note"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"For 'label' proposals where 'val' is 'needs-context', the full text of any proposed annotation (e.g. community note) to be shown below the post.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("reasons"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"An optional array of predefined reasons justifying the moderation action.",
),
),
items: LexArrayItem::String(LexString {
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sig"),
LexObjectProperty::Bytes(LexBytes { ..Default::default() }),
);
map.insert(
SmolStr::new_static("src"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"DID of the actor who created this proposal.",
),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("typ"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The type of moderation action being proposed. Currently expected values are 'allowed_user' or 'label'",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT URI of the record, repository (account), or other resource that this proposal applies to.",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("val"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"For 'label' proposals, the short string name of the value of the proposed label.",
),
),
max_length: Some(128usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("ver"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}