// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.user-intents.demo.declaration
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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::org_user_intents::demo::declaration;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Intent<'a> {
    ///indicates user intent for reuse. Note that this field is optional, and thus tri-state (true, false, undefined)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow: Option<bool>,
    ///
    pub updated_at: Datetime,
}

/// TODO

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Declaration<'a> {
    ///Inclusion of account data in bulk 'snapshot' datasets which are publicly redistributed, even if only for a fixed time period
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub bulk_dataset: Option<declaration::Intent<'a>>,
    ///Bridging account data or interactions into distinct social web protocol ecosystems
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub protocol_bridging: Option<declaration::Intent<'a>>,
    ///Public access to or replay of account data as part of archiving and preservation efforts
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub public_access_archive: Option<declaration::Intent<'a>>,
    ///Use of account data as input to machine learning models which could be used to generate synthetic content or interactions
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub synthetic_content_generation: Option<declaration::Intent<'a>>,
    ///
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
}

/// 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 DeclarationGetRecordOutput<'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: Declaration<'a>,
}

impl<'a> Declaration<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, DeclarationRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

impl<'a> LexiconSchema for Intent<'a> {
    fn nsid() -> &'static str {
        "org.user-intents.demo.declaration"
    }
    fn def_name() -> &'static str {
        "intent"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_user_intents_demo_declaration()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct DeclarationRecord;
impl XrpcResp for DeclarationRecord {
    const NSID: &'static str = "org.user-intents.demo.declaration";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = DeclarationGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<DeclarationGetRecordOutput<'_>> for Declaration<'_> {
    fn from(output: DeclarationGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Declaration<'_> {
    const NSID: &'static str = "org.user-intents.demo.declaration";
    type Record = DeclarationRecord;
}

impl Collection for DeclarationRecord {
    const NSID: &'static str = "org.user-intents.demo.declaration";
    type Record = DeclarationRecord;
}

impl<'a> LexiconSchema for Declaration<'a> {
    fn nsid() -> &'static str {
        "org.user-intents.demo.declaration"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_user_intents_demo_declaration()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod intent_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 UpdatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type UpdatedAt = Unset;
    }
    ///State transition - sets the `updated_at` field to Set
    pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
    impl<S: State> State for SetUpdatedAt<S> {
        type UpdatedAt = Set<members::updated_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `updated_at` field
        pub struct updated_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct IntentBuilder<'a, S: intent_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<bool>, Option<Datetime>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Intent<'a> {
    /// Create a new builder for this type
    pub fn new() -> IntentBuilder<'a, intent_state::Empty> {
        IntentBuilder::new()
    }
}

impl<'a> IntentBuilder<'a, intent_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        IntentBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: intent_state::State> IntentBuilder<'a, S> {
    /// Set the `allow` field (optional)
    pub fn allow(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `allow` field to an Option value (optional)
    pub fn maybe_allow(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> IntentBuilder<'a, S>
where
    S: intent_state::State,
    S::UpdatedAt: intent_state::IsUnset,
{
    /// Set the `updatedAt` field (required)
    pub fn updated_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> IntentBuilder<'a, intent_state::SetUpdatedAt<S>> {
        self._fields.1 = Option::Some(value.into());
        IntentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> IntentBuilder<'a, S>
where
    S: intent_state::State,
    S::UpdatedAt: intent_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Intent<'a> {
        Intent {
            allow: self._fields.0,
            updated_at: 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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Intent<'a> {
        Intent {
            allow: self._fields.0,
            updated_at: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_user_intents_demo_declaration() -> 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("org.user-intents.demo.declaration"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("intent"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("updatedAt")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("allow"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("updatedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("")),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(CowStr::new_static("TODO")),
                    key: Some(CowStr::new_static("literal:self")),
                    record: LexRecordRecord::Object(LexObject {
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("bulkDataset"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#intent"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("protocolBridging"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#intent"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("publicAccessArchive"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#intent"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("syntheticContentGeneration"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#intent"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("")),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod declaration_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 {}
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {}
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {}
}

/// Builder for constructing an instance of this type
pub struct DeclarationBuilder<'a, S: declaration_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<declaration::Intent<'a>>,
        Option<declaration::Intent<'a>>,
        Option<declaration::Intent<'a>>,
        Option<declaration::Intent<'a>>,
        Option<Datetime>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Declaration<'a> {
    /// Create a new builder for this type
    pub fn new() -> DeclarationBuilder<'a, declaration_state::Empty> {
        DeclarationBuilder::new()
    }
}

impl<'a> DeclarationBuilder<'a, declaration_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        DeclarationBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
    /// Set the `bulkDataset` field (optional)
    pub fn bulk_dataset(
        mut self,
        value: impl Into<Option<declaration::Intent<'a>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `bulkDataset` field to an Option value (optional)
    pub fn maybe_bulk_dataset(mut self, value: Option<declaration::Intent<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
    /// Set the `protocolBridging` field (optional)
    pub fn protocol_bridging(
        mut self,
        value: impl Into<Option<declaration::Intent<'a>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `protocolBridging` field to an Option value (optional)
    pub fn maybe_protocol_bridging(
        mut self,
        value: Option<declaration::Intent<'a>>,
    ) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
    /// Set the `publicAccessArchive` field (optional)
    pub fn public_access_archive(
        mut self,
        value: impl Into<Option<declaration::Intent<'a>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `publicAccessArchive` field to an Option value (optional)
    pub fn maybe_public_access_archive(
        mut self,
        value: Option<declaration::Intent<'a>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
    /// Set the `syntheticContentGeneration` field (optional)
    pub fn synthetic_content_generation(
        mut self,
        value: impl Into<Option<declaration::Intent<'a>>>,
    ) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `syntheticContentGeneration` field to an Option value (optional)
    pub fn maybe_synthetic_content_generation(
        mut self,
        value: Option<declaration::Intent<'a>>,
    ) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `updatedAt` field to an Option value (optional)
    pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> DeclarationBuilder<'a, S>
where
    S: declaration_state::State,
{
    /// Build the final struct
    pub fn build(self) -> Declaration<'a> {
        Declaration {
            bulk_dataset: self._fields.0,
            protocol_bridging: self._fields.1,
            public_access_archive: self._fields.2,
            synthetic_content_generation: self._fields.3,
            updated_at: self._fields.4,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Declaration<'a> {
        Declaration {
            bulk_dataset: self._fields.0,
            protocol_bridging: self._fields.1,
            public_access_archive: self._fields.2,
            synthetic_content_generation: self._fields.3,
            updated_at: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}