// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: space.litenote.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_litenote::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.litenote.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>,
    ///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>>>,
    #[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>>>,
}

/// 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.litenote.note"
    }
    fn def_name() -> &'static str {
        "image"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_space_litenote_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.litenote.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.litenote.note";
    type Record = NoteRecord;
}

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

impl<S: BosStr> LexiconSchema for Note<S> {
    fn nsid() -> &'static str {
        "space.litenote.note"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_space_litenote_note()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.content;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("content"),
                    max: 10000usize,
                    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(),
                });
            }
        }
        {
            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_litenote_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.litenote.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(10000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..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("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<S>,
        Option<i64>,
        Option<Vec<note::Image<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),
            _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),
            _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 `fontFamily` field (optional)
    pub fn font_family(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = 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.2 = 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.3 = 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.3 = 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.4 = 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.4 = 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.5 = 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.5 = 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.6 = 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.6 = 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.7 = 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,
            font_family: self._fields.2,
            font_size: self._fields.3,
            images: self._fields.4,
            published_at: self._fields.5,
            theme: self._fields.6,
            title: self._fields.7.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,
            font_family: self._fields.2,
            font_size: self._fields.3,
            images: self._fields.4,
            published_at: self._fields.5,
            theme: self._fields.6,
            title: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}