// @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, 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};
/// Scientific publication record bridged from Octopus.ac via Octosphere. Represents a single version of an Octopus publication.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "social.octosphere.publication",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Publication<S: BosStr = DefaultStr> {
    ///Public Octopus URL for the publication version.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub canonical_url: Option<UriValue<S>>,
    ///List of citation strings extracted from references.
    pub citations: Vec<S>,
    ///Raw HTML content body.
    pub content_html: S,
    ///Plain text content for compact consumption.
    pub content_text: S,
    ///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")]
    pub doi: Option<UriValue<S>>,
    ///Publication ids that link to this record.
    pub linked_from: Vec<S>,
    ///Publication ids this record links to.
    pub linked_to: Vec<S>,
    ///Octopus publication id (UUID).
    pub octopus_id: S,
    ///ORCID of the publication owner (if available).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub owner_orcid: Option<S>,
    ///Publication id this peer review references, if applicable.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub peer_review_of: Option<S>,
    ///Octopus publication type.
    pub publication_type: PublicationPublicationType<S>,
    ///Octopus publication status (expected LIVE).
    pub status: PublicationStatus<S>,
    ///Publication title.
    pub title: S,
    ///ISO timestamp of when the publication was last updated in Octopus.
    pub updated_at: Datetime,
    ///Octopus publication version id (UUID).
    pub version_id: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Octopus publication type.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum PublicationPublicationType<S: BosStr = DefaultStr> {
    ResearchProblem,
    Hypothesis,
    Protocol,
    Analysis,
    Interpretation,
    RealWorldApplication,
    Data,
    PeerReview,
    Other(S),
}

impl<S: BosStr> PublicationPublicationType<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "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(s),
        }
    }
}

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

impl<S: BosStr> AsRef<str> for PublicationPublicationType<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
for PublicationPublicationType<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for PublicationPublicationType<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for PublicationPublicationType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = PublicationPublicationType<S::Output>;
    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<S: BosStr = DefaultStr> {
    Live,
    Draft,
    Archived,
    Other(S),
}

impl<S: BosStr> PublicationStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Live => "LIVE",
            Self::Draft => "DRAFT",
            Self::Archived => "ARCHIVED",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "LIVE" => Self::Live,
            "DRAFT" => Self::Draft,
            "ARCHIVED" => Self::Archived,
            _ => Self::Other(s),
        }
    }
}

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

impl<S: BosStr> AsRef<str> for PublicationStatus<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for PublicationStatus<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for PublicationStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for PublicationStatus<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = PublicationStatus<S::Output>;
    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<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Publication<S>,
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<St: publication_state::State, S: BosStr> PublicationBuilder<St, S> {
    /// Set the `ownerOrcid` field (optional)
    pub fn owner_orcid(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<St: publication_state::State, S: BosStr> PublicationBuilder<St, S> {
    /// Set the `peerReviewOf` field (optional)
    pub fn peer_review_of(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.10 = value;
        self
    }
}

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

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

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

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

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

impl<St, S: BosStr> PublicationBuilder<St, S>
where
    St: publication_state::State,
    St::Citations: publication_state::IsSet,
    St::ContentHtml: publication_state::IsSet,
    St::ContentText: publication_state::IsSet,
    St::CreatedAt: publication_state::IsSet,
    St::LinkedFrom: publication_state::IsSet,
    St::LinkedTo: publication_state::IsSet,
    St::OctopusId: publication_state::IsSet,
    St::PublicationType: publication_state::IsSet,
    St::Status: publication_state::IsSet,
    St::Title: publication_state::IsSet,
    St::UpdatedAt: publication_state::IsSet,
    St::VersionId: publication_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Publication<S> {
        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<SmolStr, Data<S>>,
    ) -> Publication<S> {
        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()
    }
}