// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: scot.comhairle.testingPolisVoteV1
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[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_vote_v1;
/// A vote on a statement in the Polis-style deliberation system

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "scot.comhairle.testingPolisVoteV1",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct TestingPolisVoteV1<S: BosStr = DefaultStr> {
    ///Timestamp when the vote was created
    pub created_at: Datetime,
    ///Reference to the poll this vote belongs to
    pub poll: testing_polis_vote_v1::PollRef<S>,
    ///Reference to the statement being voted on
    pub subject: testing_polis_vote_v1::StatementRef<S>,
    ///The vote value
    pub value: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TestingPolisVoteV1GetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: TestingPolisVoteV1<S>,
}

/// Reference to a poll record

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PollRef<S: BosStr = DefaultStr> {
    ///Content identifier of the poll record
    pub cid: Cid<S>,
    ///AT-URI of the poll record
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Reference to a statement record

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct StatementRef<S: BosStr = DefaultStr> {
    ///Content identifier of the statement record
    pub cid: Cid<S>,
    ///AT-URI of the statement record
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> TestingPolisVoteV1<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, TestingPolisVoteV1Record>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct TestingPolisVoteV1Record;
impl XrpcResp for TestingPolisVoteV1Record {
    const NSID: &'static str = "scot.comhairle.testingPolisVoteV1";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = TestingPolisVoteV1GetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<TestingPolisVoteV1GetRecordOutput<S>> for TestingPolisVoteV1<S> {
    fn from(output: TestingPolisVoteV1GetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for TestingPolisVoteV1<S> {
    const NSID: &'static str = "scot.comhairle.testingPolisVoteV1";
    type Record = TestingPolisVoteV1Record;
}

impl Collection for TestingPolisVoteV1Record {
    const NSID: &'static str = "scot.comhairle.testingPolisVoteV1";
    type Record = TestingPolisVoteV1Record;
}

impl<S: BosStr> LexiconSchema for TestingPolisVoteV1<S> {
    fn nsid() -> &'static str {
        "scot.comhairle.testingPolisVoteV1"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_scot_comhairle_testingPolisVoteV1()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for PollRef<S> {
    fn nsid() -> &'static str {
        "scot.comhairle.testingPolisVoteV1"
    }
    fn def_name() -> &'static str {
        "pollRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_scot_comhairle_testingPolisVoteV1()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for StatementRef<S> {
    fn nsid() -> &'static str {
        "scot.comhairle.testingPolisVoteV1"
    }
    fn def_name() -> &'static str {
        "statementRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_scot_comhairle_testingPolisVoteV1()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod testing_polis_vote_v1_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type CreatedAt;
        type Poll;
        type Subject;
        type Value;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Poll = Unset;
        type Subject = Unset;
        type Value = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    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 Subject = St::Subject;
        type Value = St::Value;
    }
    ///State transition - sets the `poll` field to Set
    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 Subject = St::Subject;
        type Value = St::Value;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type CreatedAt = St::CreatedAt;
        type Poll = St::Poll;
        type Subject = Set<members::subject>;
        type Value = St::Value;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetValue<St> {}
    impl<St: State> State for SetValue<St> {
        type CreatedAt = St::CreatedAt;
        type Poll = St::Poll;
        type Subject = St::Subject;
        type Value = Set<members::value>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `poll` field
        pub struct poll(());
        ///Marker type for the `subject` field
        pub struct subject(());
        ///Marker type for the `value` field
        pub struct value(());
    }
}

/// Builder for constructing an instance of this type.
pub struct TestingPolisVoteV1Builder<
    St: testing_polis_vote_v1_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Datetime>,
        Option<testing_polis_vote_v1::PollRef<S>>,
        Option<testing_polis_vote_v1::StatementRef<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl TestingPolisVoteV1<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> TestingPolisVoteV1Builder<
        testing_polis_vote_v1_state::Empty,
        DefaultStr,
    > {
        TestingPolisVoteV1Builder::new()
    }
}

impl<S: BosStr> TestingPolisVoteV1<S> {
    /// Create a new builder for this type
    pub fn builder() -> TestingPolisVoteV1Builder<
        testing_polis_vote_v1_state::Empty,
        S,
    > {
        TestingPolisVoteV1Builder::builder()
    }
}

impl TestingPolisVoteV1Builder<testing_polis_vote_v1_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        TestingPolisVoteV1Builder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> TestingPolisVoteV1Builder<testing_polis_vote_v1_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        TestingPolisVoteV1Builder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TestingPolisVoteV1Builder<St, S>
where
    St: testing_polis_vote_v1_state::State,
    St::CreatedAt: testing_polis_vote_v1_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> TestingPolisVoteV1Builder<testing_polis_vote_v1_state::SetCreatedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        TestingPolisVoteV1Builder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TestingPolisVoteV1Builder<St, S>
where
    St: testing_polis_vote_v1_state::State,
    St::Poll: testing_polis_vote_v1_state::IsUnset,
{
    /// Set the `poll` field (required)
    pub fn poll(
        mut self,
        value: impl Into<testing_polis_vote_v1::PollRef<S>>,
    ) -> TestingPolisVoteV1Builder<testing_polis_vote_v1_state::SetPoll<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TestingPolisVoteV1Builder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TestingPolisVoteV1Builder<St, S>
where
    St: testing_polis_vote_v1_state::State,
    St::Subject: testing_polis_vote_v1_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<testing_polis_vote_v1::StatementRef<S>>,
    ) -> TestingPolisVoteV1Builder<testing_polis_vote_v1_state::SetSubject<St>, S> {
        self._fields.2 = Option::Some(value.into());
        TestingPolisVoteV1Builder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TestingPolisVoteV1Builder<St, S>
where
    St: testing_polis_vote_v1_state::State,
    St::Value: testing_polis_vote_v1_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<S>,
    ) -> TestingPolisVoteV1Builder<testing_polis_vote_v1_state::SetValue<St>, S> {
        self._fields.3 = Option::Some(value.into());
        TestingPolisVoteV1Builder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TestingPolisVoteV1Builder<St, S>
where
    St: testing_polis_vote_v1_state::State,
    St::CreatedAt: testing_polis_vote_v1_state::IsSet,
    St::Poll: testing_polis_vote_v1_state::IsSet,
    St::Subject: testing_polis_vote_v1_state::IsSet,
    St::Value: testing_polis_vote_v1_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TestingPolisVoteV1<S> {
        TestingPolisVoteV1 {
            created_at: self._fields.0.unwrap(),
            poll: self._fields.1.unwrap(),
            subject: self._fields.2.unwrap(),
            value: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> TestingPolisVoteV1<S> {
        TestingPolisVoteV1 {
            created_at: self._fields.0.unwrap(),
            poll: self._fields.1.unwrap(),
            subject: self._fields.2.unwrap(),
            value: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_scot_comhairle_testingPolisVoteV1() -> 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.testingPolisVoteV1"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A vote on a statement in the Polis-style deliberation system",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("value"),
                                SmolStr::new_static("subject"), 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 vote 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("subject"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#statementRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("value"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("The vote value")),
                                    ..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.insert(
                SmolStr::new_static("statementRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Reference to a statement 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 statement 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 statement 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 {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Cid;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `cid` field to Set
    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;
    }
    ///State transition - sets the `uri` field to Set
    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>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type.
pub struct PollRefBuilder<St: poll_ref_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Cid<S>>, Option<AtUri<S>>),
    _type: PhantomData<fn() -> S>,
}

impl PollRef<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> PollRefBuilder<poll_ref_state::Empty, DefaultStr> {
        PollRefBuilder::new()
    }
}

impl<S: BosStr> PollRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> PollRefBuilder<poll_ref_state::Empty, S> {
        PollRefBuilder::builder()
    }
}

impl PollRefBuilder<poll_ref_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        PollRefBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> PollRefBuilder<poll_ref_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        PollRefBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PollRefBuilder<St, S>
where
    St: poll_ref_state::State,
    St::Cid: poll_ref_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> PollRefBuilder<poll_ref_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        PollRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PollRefBuilder<St, S>
where
    St: poll_ref_state::State,
    St::Uri: poll_ref_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> PollRefBuilder<poll_ref_state::SetUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        PollRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PollRefBuilder<St, S>
where
    St: poll_ref_state::State,
    St::Cid: poll_ref_state::IsSet,
    St::Uri: poll_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> PollRef<S> {
        PollRef {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    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),
        }
    }
}

pub mod statement_ref_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Cid;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `cid` field to Set
    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;
    }
    ///State transition - sets the `uri` field to Set
    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>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type.
pub struct StatementRefBuilder<St: statement_ref_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Cid<S>>, Option<AtUri<S>>),
    _type: PhantomData<fn() -> S>,
}

impl StatementRef<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> StatementRefBuilder<statement_ref_state::Empty, DefaultStr> {
        StatementRefBuilder::new()
    }
}

impl<S: BosStr> StatementRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> StatementRefBuilder<statement_ref_state::Empty, S> {
        StatementRefBuilder::builder()
    }
}

impl StatementRefBuilder<statement_ref_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        StatementRefBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> StatementRefBuilder<statement_ref_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        StatementRefBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> StatementRefBuilder<St, S>
where
    St: statement_ref_state::State,
    St::Cid: statement_ref_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> StatementRefBuilder<statement_ref_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        StatementRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> StatementRefBuilder<St, S>
where
    St: statement_ref_state::State,
    St::Uri: statement_ref_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> StatementRefBuilder<statement_ref_state::SetUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        StatementRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> StatementRefBuilder<St, S>
where
    St: statement_ref_state::State,
    St::Cid: statement_ref_state::IsSet,
    St::Uri: statement_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> StatementRef<S> {
        StatementRef {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> StatementRef<S> {
        StatementRef {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}