// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: space.remanso.note
//
// 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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
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};
use crate::space_remanso::note;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Image<S: BosStr = DefaultStr> {
    ///Alt text for the image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alt: Option<S>,
    pub image: BlobRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A markdown blog post with LaTeX, GitHub notes, Mermaid, YouTube and Bluesky extensions.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "space.remanso.note",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Note<S: BosStr = DefaultStr> {
    ///Markdown content. Local image paths are replaced with blob CIDs at publish time.
    pub content: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    ///Whether the note can be discovered by others in public listings. Defaults to true.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub discoverable: Option<bool>,
    ///Font family name available from Coollabs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub font_family: Option<S>,
    ///Font size in points. Recommended range: 9–21, but clients may allow larger sizes for accessibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub font_size: Option<i64>,
    ///Blob references for images embedded in the markdown content.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub images: Option<Vec<note::Image<S>>>,
    ///Most used language in the note. In ISO 639-3 code.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<NoteLanguage<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_at: Option<Datetime>,
    ///Display theme for the note.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub theme: Option<NoteTheme<S>>,
    pub title: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Most used language in the note. In ISO 639-3 code.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NoteLanguage<S: BosStr = DefaultStr> {
    Afr,
    Ara,
    Aze,
    Bel,
    Ben,
    Bul,
    Cat,
    Ces,
    Ckb,
    Cmn,
    Dan,
    Deu,
    Ell,
    Eng,
    Est,
    Eus,
    Fin,
    Fra,
    Hau,
    Heb,
    Hin,
    Hrv,
    Hun,
    Hye,
    Ind,
    Isl,
    Ita,
    Jpn,
    Kat,
    Kaz,
    Kor,
    Lit,
    Mar,
    Mkd,
    Nld,
    Nob,
    Pes,
    Pol,
    Por,
    Ron,
    Run,
    Rus,
    Slk,
    Spa,
    Srp,
    Swe,
    Tgl,
    Tur,
    Ukr,
    Vie,
    Other(S),
}

impl<S: BosStr> NoteLanguage<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Afr => "afr",
            Self::Ara => "ara",
            Self::Aze => "aze",
            Self::Bel => "bel",
            Self::Ben => "ben",
            Self::Bul => "bul",
            Self::Cat => "cat",
            Self::Ces => "ces",
            Self::Ckb => "ckb",
            Self::Cmn => "cmn",
            Self::Dan => "dan",
            Self::Deu => "deu",
            Self::Ell => "ell",
            Self::Eng => "eng",
            Self::Est => "est",
            Self::Eus => "eus",
            Self::Fin => "fin",
            Self::Fra => "fra",
            Self::Hau => "hau",
            Self::Heb => "heb",
            Self::Hin => "hin",
            Self::Hrv => "hrv",
            Self::Hun => "hun",
            Self::Hye => "hye",
            Self::Ind => "ind",
            Self::Isl => "isl",
            Self::Ita => "ita",
            Self::Jpn => "jpn",
            Self::Kat => "kat",
            Self::Kaz => "kaz",
            Self::Kor => "kor",
            Self::Lit => "lit",
            Self::Mar => "mar",
            Self::Mkd => "mkd",
            Self::Nld => "nld",
            Self::Nob => "nob",
            Self::Pes => "pes",
            Self::Pol => "pol",
            Self::Por => "por",
            Self::Ron => "ron",
            Self::Run => "run",
            Self::Rus => "rus",
            Self::Slk => "slk",
            Self::Spa => "spa",
            Self::Srp => "srp",
            Self::Swe => "swe",
            Self::Tgl => "tgl",
            Self::Tur => "tur",
            Self::Ukr => "ukr",
            Self::Vie => "vie",
            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() {
            "afr" => Self::Afr,
            "ara" => Self::Ara,
            "aze" => Self::Aze,
            "bel" => Self::Bel,
            "ben" => Self::Ben,
            "bul" => Self::Bul,
            "cat" => Self::Cat,
            "ces" => Self::Ces,
            "ckb" => Self::Ckb,
            "cmn" => Self::Cmn,
            "dan" => Self::Dan,
            "deu" => Self::Deu,
            "ell" => Self::Ell,
            "eng" => Self::Eng,
            "est" => Self::Est,
            "eus" => Self::Eus,
            "fin" => Self::Fin,
            "fra" => Self::Fra,
            "hau" => Self::Hau,
            "heb" => Self::Heb,
            "hin" => Self::Hin,
            "hrv" => Self::Hrv,
            "hun" => Self::Hun,
            "hye" => Self::Hye,
            "ind" => Self::Ind,
            "isl" => Self::Isl,
            "ita" => Self::Ita,
            "jpn" => Self::Jpn,
            "kat" => Self::Kat,
            "kaz" => Self::Kaz,
            "kor" => Self::Kor,
            "lit" => Self::Lit,
            "mar" => Self::Mar,
            "mkd" => Self::Mkd,
            "nld" => Self::Nld,
            "nob" => Self::Nob,
            "pes" => Self::Pes,
            "pol" => Self::Pol,
            "por" => Self::Por,
            "ron" => Self::Ron,
            "run" => Self::Run,
            "rus" => Self::Rus,
            "slk" => Self::Slk,
            "spa" => Self::Spa,
            "srp" => Self::Srp,
            "swe" => Self::Swe,
            "tgl" => Self::Tgl,
            "tur" => Self::Tur,
            "ukr" => Self::Ukr,
            "vie" => Self::Vie,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for NoteLanguage<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 NoteLanguage<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 NoteLanguage<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for NoteLanguage<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = NoteLanguage<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            NoteLanguage::Afr => NoteLanguage::Afr,
            NoteLanguage::Ara => NoteLanguage::Ara,
            NoteLanguage::Aze => NoteLanguage::Aze,
            NoteLanguage::Bel => NoteLanguage::Bel,
            NoteLanguage::Ben => NoteLanguage::Ben,
            NoteLanguage::Bul => NoteLanguage::Bul,
            NoteLanguage::Cat => NoteLanguage::Cat,
            NoteLanguage::Ces => NoteLanguage::Ces,
            NoteLanguage::Ckb => NoteLanguage::Ckb,
            NoteLanguage::Cmn => NoteLanguage::Cmn,
            NoteLanguage::Dan => NoteLanguage::Dan,
            NoteLanguage::Deu => NoteLanguage::Deu,
            NoteLanguage::Ell => NoteLanguage::Ell,
            NoteLanguage::Eng => NoteLanguage::Eng,
            NoteLanguage::Est => NoteLanguage::Est,
            NoteLanguage::Eus => NoteLanguage::Eus,
            NoteLanguage::Fin => NoteLanguage::Fin,
            NoteLanguage::Fra => NoteLanguage::Fra,
            NoteLanguage::Hau => NoteLanguage::Hau,
            NoteLanguage::Heb => NoteLanguage::Heb,
            NoteLanguage::Hin => NoteLanguage::Hin,
            NoteLanguage::Hrv => NoteLanguage::Hrv,
            NoteLanguage::Hun => NoteLanguage::Hun,
            NoteLanguage::Hye => NoteLanguage::Hye,
            NoteLanguage::Ind => NoteLanguage::Ind,
            NoteLanguage::Isl => NoteLanguage::Isl,
            NoteLanguage::Ita => NoteLanguage::Ita,
            NoteLanguage::Jpn => NoteLanguage::Jpn,
            NoteLanguage::Kat => NoteLanguage::Kat,
            NoteLanguage::Kaz => NoteLanguage::Kaz,
            NoteLanguage::Kor => NoteLanguage::Kor,
            NoteLanguage::Lit => NoteLanguage::Lit,
            NoteLanguage::Mar => NoteLanguage::Mar,
            NoteLanguage::Mkd => NoteLanguage::Mkd,
            NoteLanguage::Nld => NoteLanguage::Nld,
            NoteLanguage::Nob => NoteLanguage::Nob,
            NoteLanguage::Pes => NoteLanguage::Pes,
            NoteLanguage::Pol => NoteLanguage::Pol,
            NoteLanguage::Por => NoteLanguage::Por,
            NoteLanguage::Ron => NoteLanguage::Ron,
            NoteLanguage::Run => NoteLanguage::Run,
            NoteLanguage::Rus => NoteLanguage::Rus,
            NoteLanguage::Slk => NoteLanguage::Slk,
            NoteLanguage::Spa => NoteLanguage::Spa,
            NoteLanguage::Srp => NoteLanguage::Srp,
            NoteLanguage::Swe => NoteLanguage::Swe,
            NoteLanguage::Tgl => NoteLanguage::Tgl,
            NoteLanguage::Tur => NoteLanguage::Tur,
            NoteLanguage::Ukr => NoteLanguage::Ukr,
            NoteLanguage::Vie => NoteLanguage::Vie,
            NoteLanguage::Other(v) => NoteLanguage::Other(v.into_static()),
        }
    }
}

/// Display theme for the note.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NoteTheme<S: BosStr = DefaultStr> {
    Light,
    Dark,
    Other(S),
}

impl<S: BosStr> NoteTheme<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Light => "light",
            Self::Dark => "dark",
            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() {
            "light" => Self::Light,
            "dark" => Self::Dark,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for NoteTheme<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 NoteTheme<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 NoteTheme<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for NoteTheme<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = NoteTheme<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            NoteTheme::Light => NoteTheme::Light,
            NoteTheme::Dark => NoteTheme::Dark,
            NoteTheme::Other(v) => NoteTheme::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 NoteGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Note<S>,
}

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

impl<S: BosStr> LexiconSchema for Image<S> {
    fn nsid() -> &'static str {
        "space.remanso.note"
    }
    fn def_name() -> &'static str {
        "image"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_space_remanso_note()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.alt {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.image;
            {
                let size = value.blob().size;
                if size > 2000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("image"),
                        max: 2000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.image;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/*"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("image"),
                        accepted: vec!["image/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Collection for Note<S> {
    const NSID: &'static str = "space.remanso.note";
    type Record = NoteRecord;
}

impl Collection for NoteRecord {
    const NSID: &'static str = "space.remanso.note";
    type Record = NoteRecord;
}

impl<S: BosStr> LexiconSchema for Note<S> {
    fn nsid() -> &'static str {
        "space.remanso.note"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_space_remanso_note()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.content;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 30000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("content"),
                    max: 30000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.font_family {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 200usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("font_family"),
                    max: 200usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.images {
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("images"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.language {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("language"),
                    max: 10usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            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 image_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 Image;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Image = Unset;
    }
    ///State transition - sets the `image` field to Set
    pub struct SetImage<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetImage<St> {}
    impl<St: State> State for SetImage<St> {
        type Image = Set<members::image>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `image` field
        pub struct image(());
    }
}

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

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

impl<S: BosStr> Image<S> {
    /// Create a new builder for this type
    pub fn builder() -> ImageBuilder<image_state::Empty, S> {
        ImageBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> ImageBuilder<St, S>
where
    St: image_state::State,
    St::Image: image_state::IsUnset,
{
    /// Set the `image` field (required)
    pub fn image(
        mut self,
        value: impl Into<BlobRef<S>>,
    ) -> ImageBuilder<image_state::SetImage<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ImageBuilder<St, S>
where
    St: image_state::State,
    St::Image: image_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Image<S> {
        Image {
            alt: self._fields.0,
            image: self._fields.1.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>>) -> Image<S> {
        Image {
            alt: self._fields.0,
            image: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_space_remanso_note() -> 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("space.remanso.note"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("image"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("image")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Alt text for the image."),
                                ),
                                max_length: Some(2000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("image"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A markdown blog post with LaTeX, GitHub notes, Mermaid, YouTube and Bluesky extensions.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("title"), SmolStr::new_static("content")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("content"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Markdown content. Local image paths are replaced with blob CIDs at publish time.",
                                        ),
                                    ),
                                    max_length: Some(30000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("discoverable"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("fontFamily"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Font family name available from Coollabs.",
                                        ),
                                    ),
                                    max_length: Some(200usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("fontSize"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("images"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Blob references for images embedded in the markdown content.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#image"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(20usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("language"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Most used language in the note. In ISO 639-3 code.",
                                        ),
                                    ),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("publishedAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("theme"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Display theme for the note."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    max_length: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod note_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 Content;
        type Title;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Content = Unset;
        type Title = Unset;
    }
    ///State transition - sets the `content` field to Set
    pub struct SetContent<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetContent<St> {}
    impl<St: State> State for SetContent<St> {
        type Content = Set<members::content>;
        type Title = St::Title;
    }
    ///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 Content = St::Content;
        type Title = Set<members::title>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `content` field
        pub struct content(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

/// Builder for constructing an instance of this type.
pub struct NoteBuilder<St: note_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<Datetime>,
        Option<bool>,
        Option<S>,
        Option<i64>,
        Option<Vec<note::Image<S>>>,
        Option<NoteLanguage<S>>,
        Option<Datetime>,
        Option<NoteTheme<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Note<S> {
    /// Create a new builder for this type
    pub fn builder() -> NoteBuilder<note_state::Empty, S> {
        NoteBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> NoteBuilder<St, S>
where
    St: note_state::State,
    St::Content: note_state::IsUnset,
{
    /// Set the `content` field (required)
    pub fn content(
        mut self,
        value: impl Into<S>,
    ) -> NoteBuilder<note_state::SetContent<St>, S> {
        self._fields.0 = Option::Some(value.into());
        NoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: note_state::State, S: BosStr> NoteBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `createdAt` field to an Option value (optional)
    pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: note_state::State, S: BosStr> NoteBuilder<St, S> {
    /// Set the `discoverable` field (optional)
    pub fn discoverable(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `discoverable` field to an Option value (optional)
    pub fn maybe_discoverable(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: note_state::State, S: BosStr> NoteBuilder<St, S> {
    /// Set the `fontFamily` field (optional)
    pub fn font_family(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `fontFamily` field to an Option value (optional)
    pub fn maybe_font_family(mut self, value: Option<S>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: note_state::State, S: BosStr> NoteBuilder<St, S> {
    /// Set the `fontSize` field (optional)
    pub fn font_size(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `fontSize` field to an Option value (optional)
    pub fn maybe_font_size(mut self, value: Option<i64>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: note_state::State, S: BosStr> NoteBuilder<St, S> {
    /// Set the `images` field (optional)
    pub fn images(mut self, value: impl Into<Option<Vec<note::Image<S>>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `images` field to an Option value (optional)
    pub fn maybe_images(mut self, value: Option<Vec<note::Image<S>>>) -> Self {
        self._fields.5 = value;
        self
    }
}

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

impl<St: note_state::State, S: BosStr> NoteBuilder<St, S> {
    /// Set the `publishedAt` field (optional)
    pub fn published_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `publishedAt` field to an Option value (optional)
    pub fn maybe_published_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: note_state::State, S: BosStr> NoteBuilder<St, S> {
    /// Set the `theme` field (optional)
    pub fn theme(mut self, value: impl Into<Option<NoteTheme<S>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `theme` field to an Option value (optional)
    pub fn maybe_theme(mut self, value: Option<NoteTheme<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

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

impl<St, S: BosStr> NoteBuilder<St, S>
where
    St: note_state::State,
    St::Content: note_state::IsSet,
    St::Title: note_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Note<S> {
        Note {
            content: self._fields.0.unwrap(),
            created_at: self._fields.1,
            discoverable: self._fields.2,
            font_family: self._fields.3,
            font_size: self._fields.4,
            images: self._fields.5,
            language: self._fields.6,
            published_at: self._fields.7,
            theme: self._fields.8,
            title: self._fields.9.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>>) -> Note<S> {
        Note {
            content: self._fields.0.unwrap(),
            created_at: self._fields.1,
            discoverable: self._fields.2,
            font_family: self._fields.3,
            font_size: self._fields.4,
            images: self._fields.5,
            language: self._fields.6,
            published_at: self._fields.7,
            theme: self._fields.8,
            title: self._fields.9.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}