// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: at.podping.records.startup
//
// 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, 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};
/// Normalized podping startup fields. Record TID timestamp should represent when the event was received, useful for global ordering.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Startup<'a> {
    ///Optional, e.g. 1,078
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub capacity: Option<CowStr<'a>>,
    ///Optional, e.g. https://rpc.mahdiyari.info
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub hive: Option<UriValue<'a>>,
    ///e.g. Podping startup complete
    #[serde(borrow)]
    pub message: CowStr<'a>,
    ///Optional, e.g. hivepinger
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub pinging_app: Option<CowStr<'a>>,
    ///e.g. podping.aaa
    #[serde(borrow)]
    pub server_account: CowStr<'a>,
    ///Optional, e.g. 9887936240807410000
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub session_id: Option<CowStr<'a>>,
    ///Optional source reference, minimized to save space, e.g. hive:92042659:cf11299faf19367f3f2d6bef0bf2bc4f59272506:0:podping.ccc (if mirroring the podping in hive block 92042659, transaction id cf11299faf19367f3f2d6bef0bf2bc4f59272506, first operation, hive auth podping.ccc)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub source: Option<CowStr<'a>>,
    ///Sender timestamp in ISO format, e.g. 2025-12-29T22:25:09.123Z
    pub timestamp: Datetime,
    ///Optional
    #[serde(skip_serializing_if = "Option::is_none")]
    pub use_test_node: Option<bool>,
    ///Optional, e.g. 38a44421-a535-42de-b634-d1f6edce18ce
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub uuid: Option<CowStr<'a>>,
    ///Optional, e.g. 2.1.0
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub v: Option<CowStr<'a>>,
}

/// 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 StartupGetRecordOutput<'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: Startup<'a>,
}

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct StartupRecord;
impl XrpcResp for StartupRecord {
    const NSID: &'static str = "at.podping.records.startup";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = StartupGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Startup<'_> {
    const NSID: &'static str = "at.podping.records.startup";
    type Record = StartupRecord;
}

impl Collection for StartupRecord {
    const NSID: &'static str = "at.podping.records.startup";
    type Record = StartupRecord;
}

impl<'a> LexiconSchema for Startup<'a> {
    fn nsid() -> &'static str {
        "at.podping.records.startup"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_at_podping_records_startup()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod startup_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 Message;
        type Timestamp;
        type ServerAccount;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Message = Unset;
        type Timestamp = Unset;
        type ServerAccount = Unset;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMessage<S> {}
    impl<S: State> State for SetMessage<S> {
        type Message = Set<members::message>;
        type Timestamp = S::Timestamp;
        type ServerAccount = S::ServerAccount;
    }
    ///State transition - sets the `timestamp` field to Set
    pub struct SetTimestamp<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTimestamp<S> {}
    impl<S: State> State for SetTimestamp<S> {
        type Message = S::Message;
        type Timestamp = Set<members::timestamp>;
        type ServerAccount = S::ServerAccount;
    }
    ///State transition - sets the `server_account` field to Set
    pub struct SetServerAccount<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetServerAccount<S> {}
    impl<S: State> State for SetServerAccount<S> {
        type Message = S::Message;
        type Timestamp = S::Timestamp;
        type ServerAccount = Set<members::server_account>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `message` field
        pub struct message(());
        ///Marker type for the `timestamp` field
        pub struct timestamp(());
        ///Marker type for the `server_account` field
        pub struct server_account(());
    }
}

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

impl<'a> Startup<'a> {
    /// Create a new builder for this type
    pub fn new() -> StartupBuilder<'a, startup_state::Empty> {
        StartupBuilder::new()
    }
}

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

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `capacity` field (optional)
    pub fn capacity(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `capacity` field to an Option value (optional)
    pub fn maybe_capacity(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `hive` field (optional)
    pub fn hive(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `hive` field to an Option value (optional)
    pub fn maybe_hive(mut self, value: Option<UriValue<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> StartupBuilder<'a, S>
where
    S: startup_state::State,
    S::Message: startup_state::IsUnset,
{
    /// Set the `message` field (required)
    pub fn message(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> StartupBuilder<'a, startup_state::SetMessage<S>> {
        self._fields.2 = Option::Some(value.into());
        StartupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `pingingApp` field (optional)
    pub fn pinging_app(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `pingingApp` field to an Option value (optional)
    pub fn maybe_pinging_app(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> StartupBuilder<'a, S>
where
    S: startup_state::State,
    S::ServerAccount: startup_state::IsUnset,
{
    /// Set the `serverAccount` field (required)
    pub fn server_account(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> StartupBuilder<'a, startup_state::SetServerAccount<S>> {
        self._fields.4 = Option::Some(value.into());
        StartupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `sessionId` field (optional)
    pub fn session_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `sessionId` field to an Option value (optional)
    pub fn maybe_session_id(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `source` field (optional)
    pub fn source(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `source` field to an Option value (optional)
    pub fn maybe_source(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<'a, S> StartupBuilder<'a, S>
where
    S: startup_state::State,
    S::Timestamp: startup_state::IsUnset,
{
    /// Set the `timestamp` field (required)
    pub fn timestamp(
        mut self,
        value: impl Into<Datetime>,
    ) -> StartupBuilder<'a, startup_state::SetTimestamp<S>> {
        self._fields.7 = Option::Some(value.into());
        StartupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `useTestNode` field (optional)
    pub fn use_test_node(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `useTestNode` field to an Option value (optional)
    pub fn maybe_use_test_node(mut self, value: Option<bool>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `uuid` field (optional)
    pub fn uuid(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `uuid` field to an Option value (optional)
    pub fn maybe_uuid(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<'a, S: startup_state::State> StartupBuilder<'a, S> {
    /// Set the `v` field (optional)
    pub fn v(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `v` field to an Option value (optional)
    pub fn maybe_v(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<'a, S> StartupBuilder<'a, S>
where
    S: startup_state::State,
    S::Message: startup_state::IsSet,
    S::Timestamp: startup_state::IsSet,
    S::ServerAccount: startup_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Startup<'a> {
        Startup {
            capacity: self._fields.0,
            hive: self._fields.1,
            message: self._fields.2.unwrap(),
            pinging_app: self._fields.3,
            server_account: self._fields.4.unwrap(),
            session_id: self._fields.5,
            source: self._fields.6,
            timestamp: self._fields.7.unwrap(),
            use_test_node: self._fields.8,
            uuid: self._fields.9,
            v: self._fields.10,
            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>,
        >,
    ) -> Startup<'a> {
        Startup {
            capacity: self._fields.0,
            hive: self._fields.1,
            message: self._fields.2.unwrap(),
            pinging_app: self._fields.3,
            server_account: self._fields.4.unwrap(),
            session_id: self._fields.5,
            source: self._fields.6,
            timestamp: self._fields.7.unwrap(),
            use_test_node: self._fields.8,
            uuid: self._fields.9,
            v: self._fields.10,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_at_podping_records_startup() -> 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("at.podping.records.startup"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Normalized podping startup fields. Record TID timestamp should represent when the event was received, useful for global ordering.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("serverAccount"),
                                SmolStr::new_static("message"),
                                SmolStr::new_static("timestamp")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("capacity"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Optional, e.g. 1,078"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("hive"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optional, e.g. https://rpc.mahdiyari.info",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("message"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("e.g. Podping startup complete"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("pingingApp"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Optional, e.g. hivepinger"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("serverAccount"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("e.g. podping.aaa")),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sessionId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Optional, e.g. 9887936240807410000"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("source"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optional source reference, minimized to save space, e.g. hive:92042659:cf11299faf19367f3f2d6bef0bf2bc4f59272506:0:podping.ccc (if mirroring the podping in hive block 92042659, transaction id cf11299faf19367f3f2d6bef0bf2bc4f59272506, first operation, hive auth podping.ccc)",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("timestamp"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Sender timestamp in ISO format, e.g. 2025-12-29T22:25:09.123Z",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("useTestNode"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("uuid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optional, e.g. 38a44421-a535-42de-b634-d1f6edce18ce",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("v"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Optional, e.g. 2.1.0"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}