// @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;

#[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 fields, supporting podping v0 through v1.1. 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 Podping<'a> {
    ///The updated feeds, e.g. [ "https://example.com/path/to/feed.xml" ]
    #[serde(borrow)]
    pub iris: Vec<UriValue<'a>>,
    ///Common medium, e.g. podcast
    #[serde(borrow)]
    pub medium: CowStr<'a>,
    ///Common reason, e.g. update
    #[serde(borrow)]
    pub reason: CowStr<'a>,
    ///Optional identifier for the writer session, e.g. 9624937909978522000
    #[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, 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
    #[serde(borrow)]
    pub version: 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 PodpingGetRecordOutput<'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: Podping<'a>,
}

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

/// 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<'de> = PodpingGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

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

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

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

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

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

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

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

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

impl<'a, S: podping_state::State> PodpingBuilder<'a, S> {
    /// Set the `source` field (optional)
    pub fn source(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.4 = 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.4 = value;
        self
    }
}

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

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

impl<'a, S> PodpingBuilder<'a, S>
where
    S: podping_state::State,
    S::Timestamp: podping_state::IsSet,
    S::Iris: podping_state::IsSet,
    S::Medium: podping_state::IsSet,
    S::Reason: podping_state::IsSet,
    S::Version: podping_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Podping<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Podping<'a> {
        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()
    }
}