// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: systems.timker.hawlt.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, Language};
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::systems_timker::hawlt::note;
/// An image attachment with alt text.

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

/// Record containing a Hawlt note.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "systems.timker.hawlt.note",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Note<S: BosStr = DefaultStr> {
    ///Images attached to the note. Max 4 attachments, 5MB each
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attachments: Option<Vec<note::Attachment<S>>>,
    /**The primary note content. Max 3000 graphemes, 30000 bytes
Note: large string limit is intentional for diary-style entries.*/
    pub content: S,
    ///Content warning label. When present, note content should be hidden by default. Max 100 graphemes, 1000 bytes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content_warning: Option<S>,
    ///Client-declared timestamp when this note was originally created.
    pub created_at: Datetime,
    ///Indicates human language of note primary text content.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub langs: Option<Vec<Language>>,
    ///Array of string used to tags or categorize the note. Avoid prepending with hashtags.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// 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 Attachment<S> {
    fn nsid() -> &'static str {
        "systems.timker.hawlt.note"
    }
    fn def_name() -> &'static str {
        "attachment"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_systems_timker_hawlt_note()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.alt;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.alt;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("alt"),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.image;
            {
                let size = value.blob().size;
                if size > 5000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("image"),
                        max: 5000000usize,
                        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 = "systems.timker.hawlt.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 = "systems.timker.hawlt.note";
    type Record = NoteRecord;
}

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

impl<S: BosStr> LexiconSchema for Note<S> {
    fn nsid() -> &'static str {
        "systems.timker.hawlt.note"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_systems_timker_hawlt_note()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.attachments {
            #[allow(unused_comparisons)]
            if value.len() > 4usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("attachments"),
                    max: 4usize,
                    actual: value.len(),
                });
            }
        }
        {
            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()),
                });
            }
        }
        {
            let value = &self.content;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 3000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("content"),
                        max: 3000usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.content_warning {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("content_warning"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.content_warning {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 100usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("content_warning"),
                        max: 100usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.langs {
            #[allow(unused_comparisons)]
            if value.len() > 3usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("langs"),
                    max: 3usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.tags {
            #[allow(unused_comparisons)]
            if value.len() > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tags"),
                    max: 10usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Attachment<S> {
    /// Create a new builder for this type
    pub fn builder() -> AttachmentBuilder<attachment_state::Empty, S> {
        AttachmentBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> AttachmentBuilder<St, S>
where
    St: attachment_state::State,
    St::Alt: attachment_state::IsUnset,
{
    /// Set the `alt` field (required)
    pub fn alt(
        mut self,
        value: impl Into<S>,
    ) -> AttachmentBuilder<attachment_state::SetAlt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        AttachmentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

fn lexicon_doc_systems_timker_hawlt_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("systems.timker.hawlt.note"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("attachment"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("An image attachment with alt text."),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("image"), SmolStr::new_static("alt")],
                    ),
                    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. Required for accessibility.",
                                    ),
                                ),
                                max_length: Some(10000usize),
                                max_graphemes: Some(1000usize),
                                ..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("Record containing a Hawlt note."),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("content"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("attachments"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Images attached to the note. Max 4 attachments, 5MB each",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#attachment"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(4usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("content"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The primary note content. Max 3000 graphemes, 30000 bytes\nNote: large string limit is intentional for diary-style entries.",
                                        ),
                                    ),
                                    max_length: Some(30000usize),
                                    max_graphemes: Some(3000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("contentWarning"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Content warning label. When present, note content should be hidden by default. Max 100 graphemes, 1000 bytes",
                                        ),
                                    ),
                                    max_length: Some(1000usize),
                                    max_graphemes: Some(100usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when this note was originally created.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("langs"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Indicates human language of note primary text content.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::Language),
                                        ..Default::default()
                                    }),
                                    max_length: Some(3usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tags"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Array of string used to tags or categorize the note. Avoid prepending with hashtags.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "Tag to categorize the note. Max 128 graphemes, 1280 bytes",
                                            ),
                                        ),
                                        max_length: Some(1280usize),
                                        max_graphemes: Some(128usize),
                                        ..Default::default()
                                    }),
                                    max_length: Some(10usize),
                                    ..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 CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Content = Unset;
        type CreatedAt = 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 CreatedAt = St::CreatedAt;
    }
    ///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 Content = St::Content;
        type CreatedAt = Set<members::created_at>;
    }
    /// 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 `created_at` field
        pub struct created_at(());
    }
}

/// Builder for constructing an instance of this type.
pub struct NoteBuilder<St: note_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<note::Attachment<S>>>,
        Option<S>,
        Option<S>,
        Option<Datetime>,
        Option<Vec<Language>>,
        Option<Vec<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),
            _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),
            _type: PhantomData,
        }
    }
}

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

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.1 = Option::Some(value.into());
        NoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

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

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

impl<St, S: BosStr> NoteBuilder<St, S>
where
    St: note_state::State,
    St::Content: note_state::IsSet,
    St::CreatedAt: note_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Note<S> {
        Note {
            attachments: self._fields.0,
            content: self._fields.1.unwrap(),
            content_warning: self._fields.2,
            created_at: self._fields.3.unwrap(),
            langs: self._fields.4,
            tags: self._fields.5,
            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 {
            attachments: self._fields.0,
            content: self._fields.1.unwrap(),
            content_warning: self._fields.2,
            created_at: self._fields.3.unwrap(),
            langs: self._fields.4,
            tags: self._fields.5,
            extra_data: Some(extra_data),
        }
    }
}