// @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, 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::org_user_intents::demo::declaration;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Intent<S: BosStr = DefaultStr> {
    ///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,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// TODO

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "org.user-intents.demo.declaration",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Declaration<S: BosStr = DefaultStr> {
    ///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")]
    pub bulk_dataset: Option<declaration::Intent<S>>,
    ///Bridging account data or interactions into distinct social web protocol ecosystems
    #[serde(skip_serializing_if = "Option::is_none")]
    pub protocol_bridging: Option<declaration::Intent<S>>,
    ///Public access to or replay of account data as part of archiving and preservation efforts
    #[serde(skip_serializing_if = "Option::is_none")]
    pub public_access_archive: Option<declaration::Intent<S>>,
    ///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")]
    pub synthetic_content_generation: Option<declaration::Intent<S>>,
    ///
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    #[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 DeclarationGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Declaration<S>,
}

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

impl<S: BosStr> LexiconSchema for Intent<S> {
    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<S: BosStr> = DeclarationGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Declaration<S> {
    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<S: BosStr> LexiconSchema for Declaration<S> {
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
    impl<St: State> State for SetUpdatedAt<St> {
        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<St: intent_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<bool>, Option<Datetime>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St: intent_state::State, S: BosStr> IntentBuilder<St, 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<St, S: BosStr> IntentBuilder<St, S>
where
    St: intent_state::State,
    St::UpdatedAt: intent_state::IsUnset,
{
    /// Set the `updatedAt` field (required)
    pub fn updated_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> IntentBuilder<intent_state::SetUpdatedAt<St>, S> {
        self._fields.1 = Option::Some(value.into());
        IntentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> IntentBuilder<St, S>
where
    St: intent_state::State,
    St::UpdatedAt: intent_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Intent<S> {
        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<SmolStr, Data<S>>) -> Intent<S> {
        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<St: declaration_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<declaration::Intent<S>>,
        Option<declaration::Intent<S>>,
        Option<declaration::Intent<S>>,
        Option<declaration::Intent<S>>,
        Option<Datetime>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St: declaration_state::State, S: BosStr> DeclarationBuilder<St, S> {
    /// Set the `bulkDataset` field (optional)
    pub fn bulk_dataset(
        mut self,
        value: impl Into<Option<declaration::Intent<S>>>,
    ) -> 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<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: declaration_state::State, S: BosStr> DeclarationBuilder<St, S> {
    /// Set the `protocolBridging` field (optional)
    pub fn protocol_bridging(
        mut self,
        value: impl Into<Option<declaration::Intent<S>>>,
    ) -> 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<S>>,
    ) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: declaration_state::State, S: BosStr> DeclarationBuilder<St, S> {
    /// Set the `publicAccessArchive` field (optional)
    pub fn public_access_archive(
        mut self,
        value: impl Into<Option<declaration::Intent<S>>>,
    ) -> 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<S>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: declaration_state::State, S: BosStr> DeclarationBuilder<St, S> {
    /// Set the `syntheticContentGeneration` field (optional)
    pub fn synthetic_content_generation(
        mut self,
        value: impl Into<Option<declaration::Intent<S>>>,
    ) -> 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<S>>,
    ) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: declaration_state::State, S: BosStr> DeclarationBuilder<St, 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<St, S: BosStr> DeclarationBuilder<St, S>
where
    St: declaration_state::State,
{
    /// Build the final struct.
    pub fn build(self) -> Declaration<S> {
        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<SmolStr, Data<S>>,
    ) -> Declaration<S> {
        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),
        }
    }
}