// @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, 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, UriValue};
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};
/// Normalized podping startup fields. Record TID timestamp should represent when the event was received, useful for global ordering.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "at.podping.records.startup",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Startup<S: BosStr = DefaultStr> {
    ///Optional, e.g. 1,078
    #[serde(skip_serializing_if = "Option::is_none")]
    pub capacity: Option<S>,
    ///Optional, e.g. https://rpc.mahdiyari.info
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hive: Option<UriValue<S>>,
    ///e.g. Podping startup complete
    pub message: S,
    ///Optional, e.g. hivepinger
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pinging_app: Option<S>,
    ///e.g. podping.aaa
    pub server_account: S,
    ///Optional, e.g. 9887936240807410000
    #[serde(skip_serializing_if = "Option::is_none")]
    pub session_id: Option<S>,
    ///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")]
    pub source: Option<S>,
    ///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")]
    pub uuid: Option<S>,
    ///Optional, e.g. 2.1.0
    #[serde(skip_serializing_if = "Option::is_none")]
    pub v: Option<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 StartupGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Startup<S>,
}

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

/// 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<S: BosStr> = StartupGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Startup<S> {
    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<S: BosStr> LexiconSchema for Startup<S> {
    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 ServerAccount;
        type Timestamp;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Message = Unset;
        type ServerAccount = Unset;
        type Timestamp = Unset;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMessage<St> {}
    impl<St: State> State for SetMessage<St> {
        type Message = Set<members::message>;
        type ServerAccount = St::ServerAccount;
        type Timestamp = St::Timestamp;
    }
    ///State transition - sets the `server_account` field to Set
    pub struct SetServerAccount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetServerAccount<St> {}
    impl<St: State> State for SetServerAccount<St> {
        type Message = St::Message;
        type ServerAccount = Set<members::server_account>;
        type Timestamp = St::Timestamp;
    }
    ///State transition - sets the `timestamp` field to Set
    pub struct SetTimestamp<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTimestamp<St> {}
    impl<St: State> State for SetTimestamp<St> {
        type Message = St::Message;
        type ServerAccount = St::ServerAccount;
        type Timestamp = Set<members::timestamp>;
    }
    /// 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 `server_account` field
        pub struct server_account(());
        ///Marker type for the `timestamp` field
        pub struct timestamp(());
    }
}

/// Builder for constructing an instance of this type.
pub struct StartupBuilder<St: startup_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<UriValue<S>>,
        Option<S>,
        Option<S>,
        Option<S>,
        Option<S>,
        Option<S>,
        Option<Datetime>,
        Option<bool>,
        Option<S>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St: startup_state::State, S: BosStr> StartupBuilder<St, S> {
    /// Set the `hive` field (optional)
    pub fn hive(mut self, value: impl Into<Option<UriValue<S>>>) -> 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<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<St: startup_state::State, S: BosStr> StartupBuilder<St, S> {
    /// Set the `pingingApp` field (optional)
    pub fn pinging_app(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<St: startup_state::State, S: BosStr> StartupBuilder<St, S> {
    /// Set the `sessionId` field (optional)
    pub fn session_id(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.5 = value;
        self
    }
}

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

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

impl<St: startup_state::State, S: BosStr> StartupBuilder<St, 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<St: startup_state::State, S: BosStr> StartupBuilder<St, S> {
    /// Set the `uuid` field (optional)
    pub fn uuid(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `uuid` field to an Option value (optional)
    pub fn maybe_uuid(mut self, value: Option<S>) -> Self {
        self._fields.9 = value;
        self
    }
}

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

impl<St, S: BosStr> StartupBuilder<St, S>
where
    St: startup_state::State,
    St::Message: startup_state::IsSet,
    St::ServerAccount: startup_state::IsSet,
    St::Timestamp: startup_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Startup<S> {
        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<SmolStr, Data<S>>) -> Startup<S> {
        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()
    }
}