// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: social.octosphere.publication
//
// 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};
/// Scientific publication record bridged from Octopus.ac via Octosphere. Represents a single version of an Octopus publication.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Publication<'a> {
    ///Public Octopus URL for the publication version.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub canonical_url: Option<UriValue<'a>>,
    ///List of citation strings extracted from references.
    #[serde(borrow)]
    pub citations: Vec<CowStr<'a>>,
    ///Raw HTML content body.
    #[serde(borrow)]
    pub content_html: CowStr<'a>,
    ///Plain text content for compact consumption.
    #[serde(borrow)]
    pub content_text: CowStr<'a>,
    ///ISO timestamp of when the publication was created in Octopus.
    pub created_at: Datetime,
    ///Publication version DOI URL, if present.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub doi: Option<UriValue<'a>>,
    ///Publication ids that link to this record.
    #[serde(borrow)]
    pub linked_from: Vec<CowStr<'a>>,
    ///Publication ids this record links to.
    #[serde(borrow)]
    pub linked_to: Vec<CowStr<'a>>,
    ///Octopus publication id (UUID).
    #[serde(borrow)]
    pub octopus_id: CowStr<'a>,
    ///ORCID of the publication owner (if available).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub owner_orcid: Option<CowStr<'a>>,
    ///Publication id this peer review references, if applicable.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub peer_review_of: Option<CowStr<'a>>,
    ///Octopus publication type.
    #[serde(borrow)]
    pub publication_type: PublicationPublicationType<'a>,
    ///Octopus publication status (expected LIVE).
    #[serde(borrow)]
    pub status: PublicationStatus<'a>,
    ///Publication title.
    #[serde(borrow)]
    pub title: CowStr<'a>,
    ///ISO timestamp of when the publication was last updated in Octopus.
    pub updated_at: Datetime,
    ///Octopus publication version id (UUID).
    #[serde(borrow)]
    pub version_id: CowStr<'a>,
}

/// Octopus publication type.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum PublicationPublicationType<'a> {
    ResearchProblem,
    Hypothesis,
    Protocol,
    Analysis,
    Interpretation,
    RealWorldApplication,
    Data,
    PeerReview,
    Other(CowStr<'a>),
}

impl<'a> PublicationPublicationType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::ResearchProblem => "RESEARCH_PROBLEM",
            Self::Hypothesis => "HYPOTHESIS",
            Self::Protocol => "PROTOCOL",
            Self::Analysis => "ANALYSIS",
            Self::Interpretation => "INTERPRETATION",
            Self::RealWorldApplication => "REAL_WORLD_APPLICATION",
            Self::Data => "DATA",
            Self::PeerReview => "PEER_REVIEW",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for PublicationPublicationType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "RESEARCH_PROBLEM" => Self::ResearchProblem,
            "HYPOTHESIS" => Self::Hypothesis,
            "PROTOCOL" => Self::Protocol,
            "ANALYSIS" => Self::Analysis,
            "INTERPRETATION" => Self::Interpretation,
            "REAL_WORLD_APPLICATION" => Self::RealWorldApplication,
            "DATA" => Self::Data,
            "PEER_REVIEW" => Self::PeerReview,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for PublicationPublicationType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "RESEARCH_PROBLEM" => Self::ResearchProblem,
            "HYPOTHESIS" => Self::Hypothesis,
            "PROTOCOL" => Self::Protocol,
            "ANALYSIS" => Self::Analysis,
            "INTERPRETATION" => Self::Interpretation,
            "REAL_WORLD_APPLICATION" => Self::RealWorldApplication,
            "DATA" => Self::Data,
            "PEER_REVIEW" => Self::PeerReview,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for PublicationPublicationType<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for PublicationPublicationType<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for PublicationPublicationType<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for PublicationPublicationType<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for PublicationPublicationType<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for PublicationPublicationType<'_> {
    type Output = PublicationPublicationType<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            PublicationPublicationType::ResearchProblem => {
                PublicationPublicationType::ResearchProblem
            }
            PublicationPublicationType::Hypothesis => {
                PublicationPublicationType::Hypothesis
            }
            PublicationPublicationType::Protocol => PublicationPublicationType::Protocol,
            PublicationPublicationType::Analysis => PublicationPublicationType::Analysis,
            PublicationPublicationType::Interpretation => {
                PublicationPublicationType::Interpretation
            }
            PublicationPublicationType::RealWorldApplication => {
                PublicationPublicationType::RealWorldApplication
            }
            PublicationPublicationType::Data => PublicationPublicationType::Data,
            PublicationPublicationType::PeerReview => {
                PublicationPublicationType::PeerReview
            }
            PublicationPublicationType::Other(v) => {
                PublicationPublicationType::Other(v.into_static())
            }
        }
    }
}

/// Octopus publication status (expected LIVE).

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum PublicationStatus<'a> {
    Live,
    Draft,
    Archived,
    Other(CowStr<'a>),
}

impl<'a> PublicationStatus<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Live => "LIVE",
            Self::Draft => "DRAFT",
            Self::Archived => "ARCHIVED",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for PublicationStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "LIVE" => Self::Live,
            "DRAFT" => Self::Draft,
            "ARCHIVED" => Self::Archived,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for PublicationStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "LIVE" => Self::Live,
            "DRAFT" => Self::Draft,
            "ARCHIVED" => Self::Archived,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for PublicationStatus<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for PublicationStatus<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for PublicationStatus<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for PublicationStatus<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for PublicationStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for PublicationStatus<'_> {
    type Output = PublicationStatus<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            PublicationStatus::Live => PublicationStatus::Live,
            PublicationStatus::Draft => PublicationStatus::Draft,
            PublicationStatus::Archived => PublicationStatus::Archived,
            PublicationStatus::Other(v) => PublicationStatus::Other(v.into_static()),
        }
    }
}

/// 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 PublicationGetRecordOutput<'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: Publication<'a>,
}

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct PublicationRecord;
impl XrpcResp for PublicationRecord {
    const NSID: &'static str = "social.octosphere.publication";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = PublicationGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Publication<'_> {
    const NSID: &'static str = "social.octosphere.publication";
    type Record = PublicationRecord;
}

impl Collection for PublicationRecord {
    const NSID: &'static str = "social.octosphere.publication";
    type Record = PublicationRecord;
}

impl<'a> LexiconSchema for Publication<'a> {
    fn nsid() -> &'static str {
        "social.octosphere.publication"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_social_octosphere_publication()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.title;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod publication_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 CreatedAt;
        type UpdatedAt;
        type Citations;
        type Status;
        type OctopusId;
        type ContentHtml;
        type LinkedTo;
        type VersionId;
        type Title;
        type LinkedFrom;
        type PublicationType;
        type ContentText;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type UpdatedAt = Unset;
        type Citations = Unset;
        type Status = Unset;
        type OctopusId = Unset;
        type ContentHtml = Unset;
        type LinkedTo = Unset;
        type VersionId = Unset;
        type Title = Unset;
        type LinkedFrom = Unset;
        type PublicationType = Unset;
        type ContentText = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type CreatedAt = Set<members::created_at>;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `updated_at` field to Set
    pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
    impl<S: State> State for SetUpdatedAt<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = Set<members::updated_at>;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `citations` field to Set
    pub struct SetCitations<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCitations<S> {}
    impl<S: State> State for SetCitations<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = Set<members::citations>;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `status` field to Set
    pub struct SetStatus<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStatus<S> {}
    impl<S: State> State for SetStatus<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = Set<members::status>;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `octopus_id` field to Set
    pub struct SetOctopusId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetOctopusId<S> {}
    impl<S: State> State for SetOctopusId<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = Set<members::octopus_id>;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `content_html` field to Set
    pub struct SetContentHtml<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContentHtml<S> {}
    impl<S: State> State for SetContentHtml<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = Set<members::content_html>;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `linked_to` field to Set
    pub struct SetLinkedTo<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLinkedTo<S> {}
    impl<S: State> State for SetLinkedTo<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = Set<members::linked_to>;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `version_id` field to Set
    pub struct SetVersionId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetVersionId<S> {}
    impl<S: State> State for SetVersionId<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = Set<members::version_id>;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTitle<S> {}
    impl<S: State> State for SetTitle<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = Set<members::title>;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `linked_from` field to Set
    pub struct SetLinkedFrom<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLinkedFrom<S> {}
    impl<S: State> State for SetLinkedFrom<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = Set<members::linked_from>;
        type PublicationType = S::PublicationType;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `publication_type` field to Set
    pub struct SetPublicationType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPublicationType<S> {}
    impl<S: State> State for SetPublicationType<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = Set<members::publication_type>;
        type ContentText = S::ContentText;
    }
    ///State transition - sets the `content_text` field to Set
    pub struct SetContentText<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContentText<S> {}
    impl<S: State> State for SetContentText<S> {
        type CreatedAt = S::CreatedAt;
        type UpdatedAt = S::UpdatedAt;
        type Citations = S::Citations;
        type Status = S::Status;
        type OctopusId = S::OctopusId;
        type ContentHtml = S::ContentHtml;
        type LinkedTo = S::LinkedTo;
        type VersionId = S::VersionId;
        type Title = S::Title;
        type LinkedFrom = S::LinkedFrom;
        type PublicationType = S::PublicationType;
        type ContentText = Set<members::content_text>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `updated_at` field
        pub struct updated_at(());
        ///Marker type for the `citations` field
        pub struct citations(());
        ///Marker type for the `status` field
        pub struct status(());
        ///Marker type for the `octopus_id` field
        pub struct octopus_id(());
        ///Marker type for the `content_html` field
        pub struct content_html(());
        ///Marker type for the `linked_to` field
        pub struct linked_to(());
        ///Marker type for the `version_id` field
        pub struct version_id(());
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `linked_from` field
        pub struct linked_from(());
        ///Marker type for the `publication_type` field
        pub struct publication_type(());
        ///Marker type for the `content_text` field
        pub struct content_text(());
    }
}

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

impl<'a> Publication<'a> {
    /// Create a new builder for this type
    pub fn new() -> PublicationBuilder<'a, publication_state::Empty> {
        PublicationBuilder::new()
    }
}

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

impl<'a, S: publication_state::State> PublicationBuilder<'a, S> {
    /// Set the `canonicalUrl` field (optional)
    pub fn canonical_url(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `canonicalUrl` field to an Option value (optional)
    pub fn maybe_canonical_url(mut self, value: Option<UriValue<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::Citations: publication_state::IsUnset,
{
    /// Set the `citations` field (required)
    pub fn citations(
        mut self,
        value: impl Into<Vec<CowStr<'a>>>,
    ) -> PublicationBuilder<'a, publication_state::SetCitations<S>> {
        self._fields.1 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::ContentHtml: publication_state::IsUnset,
{
    /// Set the `contentHtml` field (required)
    pub fn content_html(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> PublicationBuilder<'a, publication_state::SetContentHtml<S>> {
        self._fields.2 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::ContentText: publication_state::IsUnset,
{
    /// Set the `contentText` field (required)
    pub fn content_text(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> PublicationBuilder<'a, publication_state::SetContentText<S>> {
        self._fields.3 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::CreatedAt: publication_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> PublicationBuilder<'a, publication_state::SetCreatedAt<S>> {
        self._fields.4 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: publication_state::State> PublicationBuilder<'a, S> {
    /// Set the `doi` field (optional)
    pub fn doi(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `doi` field to an Option value (optional)
    pub fn maybe_doi(mut self, value: Option<UriValue<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::LinkedFrom: publication_state::IsUnset,
{
    /// Set the `linkedFrom` field (required)
    pub fn linked_from(
        mut self,
        value: impl Into<Vec<CowStr<'a>>>,
    ) -> PublicationBuilder<'a, publication_state::SetLinkedFrom<S>> {
        self._fields.6 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::LinkedTo: publication_state::IsUnset,
{
    /// Set the `linkedTo` field (required)
    pub fn linked_to(
        mut self,
        value: impl Into<Vec<CowStr<'a>>>,
    ) -> PublicationBuilder<'a, publication_state::SetLinkedTo<S>> {
        self._fields.7 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::OctopusId: publication_state::IsUnset,
{
    /// Set the `octopusId` field (required)
    pub fn octopus_id(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> PublicationBuilder<'a, publication_state::SetOctopusId<S>> {
        self._fields.8 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::PublicationType: publication_state::IsUnset,
{
    /// Set the `publicationType` field (required)
    pub fn publication_type(
        mut self,
        value: impl Into<PublicationPublicationType<'a>>,
    ) -> PublicationBuilder<'a, publication_state::SetPublicationType<S>> {
        self._fields.11 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::Status: publication_state::IsUnset,
{
    /// Set the `status` field (required)
    pub fn status(
        mut self,
        value: impl Into<PublicationStatus<'a>>,
    ) -> PublicationBuilder<'a, publication_state::SetStatus<S>> {
        self._fields.12 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::Title: publication_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> PublicationBuilder<'a, publication_state::SetTitle<S>> {
        self._fields.13 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::UpdatedAt: publication_state::IsUnset,
{
    /// Set the `updatedAt` field (required)
    pub fn updated_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> PublicationBuilder<'a, publication_state::SetUpdatedAt<S>> {
        self._fields.14 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::VersionId: publication_state::IsUnset,
{
    /// Set the `versionId` field (required)
    pub fn version_id(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> PublicationBuilder<'a, publication_state::SetVersionId<S>> {
        self._fields.15 = Option::Some(value.into());
        PublicationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PublicationBuilder<'a, S>
where
    S: publication_state::State,
    S::CreatedAt: publication_state::IsSet,
    S::UpdatedAt: publication_state::IsSet,
    S::Citations: publication_state::IsSet,
    S::Status: publication_state::IsSet,
    S::OctopusId: publication_state::IsSet,
    S::ContentHtml: publication_state::IsSet,
    S::LinkedTo: publication_state::IsSet,
    S::VersionId: publication_state::IsSet,
    S::Title: publication_state::IsSet,
    S::LinkedFrom: publication_state::IsSet,
    S::PublicationType: publication_state::IsSet,
    S::ContentText: publication_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Publication<'a> {
        Publication {
            canonical_url: self._fields.0,
            citations: self._fields.1.unwrap(),
            content_html: self._fields.2.unwrap(),
            content_text: self._fields.3.unwrap(),
            created_at: self._fields.4.unwrap(),
            doi: self._fields.5,
            linked_from: self._fields.6.unwrap(),
            linked_to: self._fields.7.unwrap(),
            octopus_id: self._fields.8.unwrap(),
            owner_orcid: self._fields.9,
            peer_review_of: self._fields.10,
            publication_type: self._fields.11.unwrap(),
            status: self._fields.12.unwrap(),
            title: self._fields.13.unwrap(),
            updated_at: self._fields.14.unwrap(),
            version_id: self._fields.15.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>,
        >,
    ) -> Publication<'a> {
        Publication {
            canonical_url: self._fields.0,
            citations: self._fields.1.unwrap(),
            content_html: self._fields.2.unwrap(),
            content_text: self._fields.3.unwrap(),
            created_at: self._fields.4.unwrap(),
            doi: self._fields.5,
            linked_from: self._fields.6.unwrap(),
            linked_to: self._fields.7.unwrap(),
            octopus_id: self._fields.8.unwrap(),
            owner_orcid: self._fields.9,
            peer_review_of: self._fields.10,
            publication_type: self._fields.11.unwrap(),
            status: self._fields.12.unwrap(),
            title: self._fields.13.unwrap(),
            updated_at: self._fields.14.unwrap(),
            version_id: self._fields.15.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_social_octosphere_publication() -> 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("social.octosphere.publication"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Scientific publication record bridged from Octopus.ac via Octosphere. Represents a single version of an Octopus publication.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("octopusId"),
                                SmolStr::new_static("versionId"),
                                SmolStr::new_static("publicationType"),
                                SmolStr::new_static("title"), SmolStr::new_static("status"),
                                SmolStr::new_static("contentHtml"),
                                SmolStr::new_static("contentText"),
                                SmolStr::new_static("citations"),
                                SmolStr::new_static("linkedTo"),
                                SmolStr::new_static("linkedFrom"),
                                SmolStr::new_static("createdAt"),
                                SmolStr::new_static("updatedAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("canonicalUrl"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Public Octopus URL for the publication version.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("citations"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "List of citation strings extracted from references.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("contentHtml"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Raw HTML content body."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("contentText"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Plain text content for compact consumption.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "ISO timestamp of when the publication was created in Octopus.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("doi"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Publication version DOI URL, if present.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("linkedFrom"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Publication ids that link to this record.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("linkedTo"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("Publication ids this record links to."),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("octopusId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Octopus publication id (UUID)."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("ownerOrcid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "ORCID of the publication owner (if available).",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("peerReviewOf"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Publication id this peer review references, if applicable.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("publicationType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Octopus publication type."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("status"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Octopus publication status (expected LIVE).",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("Publication title.")),
                                    max_length: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "ISO timestamp of when the publication was last updated in Octopus.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("versionId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Octopus publication version id (UUID)."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}