// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: at.podping.records.podping
//
// 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 fields, supporting podping v0 through v1.1. 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.podping",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Podping<S: BosStr = DefaultStr> {
    ///The updated feeds, e.g. [ "https://example.com/path/to/feed.xml" ]
    pub iris: Vec<UriValue<S>>,
    ///Common medium, e.g. podcast
    pub medium: S,
    ///Common reason, e.g. update
    pub reason: S,
    ///Optional identifier for the writer session, e.g. 9624937909978522000
    #[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, untrustworthy due to client bugs, not so useful for global ordering, in either millisecond (3 decimals) or nanosecond precision (9 decimals), e.g. 2025-12-29T22:25:09.123456789Z
    pub timestamp: Datetime,
    ///Podping schema version, e.g. 1.1
    pub version: 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 PodpingGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Podping<S>,
}

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

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

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

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

impl<S: BosStr> Collection for Podping<S> {
    const NSID: &'static str = "at.podping.records.podping";
    type Record = PodpingRecord;
}

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

impl<S: BosStr> LexiconSchema for Podping<S> {
    fn nsid() -> &'static str {
        "at.podping.records.podping"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_at_podping_records_podping()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod podping_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 Iris;
        type Medium;
        type Reason;
        type Timestamp;
        type Version;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Iris = Unset;
        type Medium = Unset;
        type Reason = Unset;
        type Timestamp = Unset;
        type Version = Unset;
    }
    ///State transition - sets the `iris` field to Set
    pub struct SetIris<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetIris<St> {}
    impl<St: State> State for SetIris<St> {
        type Iris = Set<members::iris>;
        type Medium = St::Medium;
        type Reason = St::Reason;
        type Timestamp = St::Timestamp;
        type Version = St::Version;
    }
    ///State transition - sets the `medium` field to Set
    pub struct SetMedium<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMedium<St> {}
    impl<St: State> State for SetMedium<St> {
        type Iris = St::Iris;
        type Medium = Set<members::medium>;
        type Reason = St::Reason;
        type Timestamp = St::Timestamp;
        type Version = St::Version;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReason<St> {}
    impl<St: State> State for SetReason<St> {
        type Iris = St::Iris;
        type Medium = St::Medium;
        type Reason = Set<members::reason>;
        type Timestamp = St::Timestamp;
        type Version = St::Version;
    }
    ///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 Iris = St::Iris;
        type Medium = St::Medium;
        type Reason = St::Reason;
        type Timestamp = Set<members::timestamp>;
        type Version = St::Version;
    }
    ///State transition - sets the `version` field to Set
    pub struct SetVersion<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetVersion<St> {}
    impl<St: State> State for SetVersion<St> {
        type Iris = St::Iris;
        type Medium = St::Medium;
        type Reason = St::Reason;
        type Timestamp = St::Timestamp;
        type Version = Set<members::version>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `iris` field
        pub struct iris(());
        ///Marker type for the `medium` field
        pub struct medium(());
        ///Marker type for the `reason` field
        pub struct reason(());
        ///Marker type for the `timestamp` field
        pub struct timestamp(());
        ///Marker type for the `version` field
        pub struct version(());
    }
}

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

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

impl<S: BosStr> Podping<S> {
    /// Create a new builder for this type
    pub fn builder() -> PodpingBuilder<podping_state::Empty, S> {
        PodpingBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> PodpingBuilder<St, S>
where
    St: podping_state::State,
    St::Iris: podping_state::IsUnset,
{
    /// Set the `iris` field (required)
    pub fn iris(
        mut self,
        value: impl Into<Vec<UriValue<S>>>,
    ) -> PodpingBuilder<podping_state::SetIris<St>, S> {
        self._fields.0 = Option::Some(value.into());
        PodpingBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PodpingBuilder<St, S>
where
    St: podping_state::State,
    St::Medium: podping_state::IsUnset,
{
    /// Set the `medium` field (required)
    pub fn medium(
        mut self,
        value: impl Into<S>,
    ) -> PodpingBuilder<podping_state::SetMedium<St>, S> {
        self._fields.1 = Option::Some(value.into());
        PodpingBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PodpingBuilder<St, S>
where
    St: podping_state::State,
    St::Reason: podping_state::IsUnset,
{
    /// Set the `reason` field (required)
    pub fn reason(
        mut self,
        value: impl Into<S>,
    ) -> PodpingBuilder<podping_state::SetReason<St>, S> {
        self._fields.2 = Option::Some(value.into());
        PodpingBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

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

impl<St, S: BosStr> PodpingBuilder<St, S>
where
    St: podping_state::State,
    St::Version: podping_state::IsUnset,
{
    /// Set the `version` field (required)
    pub fn version(
        mut self,
        value: impl Into<S>,
    ) -> PodpingBuilder<podping_state::SetVersion<St>, S> {
        self._fields.6 = Option::Some(value.into());
        PodpingBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PodpingBuilder<St, S>
where
    St: podping_state::State,
    St::Iris: podping_state::IsSet,
    St::Medium: podping_state::IsSet,
    St::Reason: podping_state::IsSet,
    St::Timestamp: podping_state::IsSet,
    St::Version: podping_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Podping<S> {
        Podping {
            iris: self._fields.0.unwrap(),
            medium: self._fields.1.unwrap(),
            reason: self._fields.2.unwrap(),
            session_id: self._fields.3,
            source: self._fields.4,
            timestamp: self._fields.5.unwrap(),
            version: self._fields.6.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>>) -> Podping<S> {
        Podping {
            iris: self._fields.0.unwrap(),
            medium: self._fields.1.unwrap(),
            reason: self._fields.2.unwrap(),
            session_id: self._fields.3,
            source: self._fields.4,
            timestamp: self._fields.5.unwrap(),
            version: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_at_podping_records_podping() -> 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.podping"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Normalized podping fields, supporting podping v0 through v1.1. 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("version"),
                                SmolStr::new_static("medium"),
                                SmolStr::new_static("reason"), SmolStr::new_static("iris"),
                                SmolStr::new_static("timestamp")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("iris"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "The updated feeds, e.g. [ \"https://example.com/path/to/feed.xml\" ]",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::Uri),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("medium"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Common medium, e.g. podcast"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("reason"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Common reason, e.g. update"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sessionId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optional identifier for the writer session, e.g. 9624937909978522000",
                                        ),
                                    ),
                                    ..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, untrustworthy due to client bugs, not so useful for global ordering, in either millisecond (3 decimals) or nanosecond precision (9 decimals), e.g. 2025-12-29T22:25:09.123456789Z",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("version"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Podping schema version, e.g. 1.1"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}