// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.whtwnd.blog.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

//! Generated bindings for the `com.whtwnd.blog` Lexicon namespace/module.
pub mod entry;
pub mod get_author_posts;
pub mod get_entry_metadata_by_name;
pub mod get_mentions_by_entry;
pub mod notify_of_new_entry;


#[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::string::{AtUri, Datetime, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct BlobMetadata<S: BosStr = DefaultStr> {
    pub blobref: BlobRef<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct BlogEntry<S: BosStr = DefaultStr> {
    pub content: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Comment<S: BosStr = DefaultStr> {
    pub content: S,
    pub entry_uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Ogp<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<i64>,
    pub url: UriValue<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for BlobMetadata<S> {
    fn nsid() -> &'static str {
        "com.whtwnd.blog.defs"
    }
    fn def_name() -> &'static str {
        "blobMetadata"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_whtwnd_blog_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.blobref;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["*/*"];
                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("blobref"),
                        accepted: vec!["*/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for BlogEntry<S> {
    fn nsid() -> &'static str {
        "com.whtwnd.blog.defs"
    }
    fn def_name() -> &'static str {
        "blogEntry"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_whtwnd_blog_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.content;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("content"),
                    max: 100000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Comment<S> {
    fn nsid() -> &'static str {
        "com.whtwnd.blog.defs"
    }
    fn def_name() -> &'static str {
        "comment"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_whtwnd_blog_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.content;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("content"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Ogp<S> {
    fn nsid() -> &'static str {
        "com.whtwnd.blog.defs"
    }
    fn def_name() -> &'static str {
        "ogp"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_whtwnd_blog_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> BlobMetadata<S> {
    /// Create a new builder for this type
    pub fn builder() -> BlobMetadataBuilder<blob_metadata_state::Empty, S> {
        BlobMetadataBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> BlobMetadataBuilder<St, S>
where
    St: blob_metadata_state::State,
    St::Blobref: blob_metadata_state::IsUnset,
{
    /// Set the `blobref` field (required)
    pub fn blobref(
        mut self,
        value: impl Into<BlobRef<S>>,
    ) -> BlobMetadataBuilder<blob_metadata_state::SetBlobref<St>, S> {
        self._fields.0 = Option::Some(value.into());
        BlobMetadataBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: blob_metadata_state::State, S: BosStr> BlobMetadataBuilder<St, S> {
    /// Set the `name` field (optional)
    pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `name` field to an Option value (optional)
    pub fn maybe_name(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> BlobMetadataBuilder<St, S>
where
    St: blob_metadata_state::State,
    St::Blobref: blob_metadata_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> BlobMetadata<S> {
        BlobMetadata {
            blobref: self._fields.0.unwrap(),
            name: self._fields.1,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> BlobMetadata<S> {
        BlobMetadata {
            blobref: self._fields.0.unwrap(),
            name: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_whtwnd_blog_defs() -> 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("com.whtwnd.blog.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("blobMetadata"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("blobref")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("blobref"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("blogEntry"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("content")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("content"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(100000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("comment"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("content"),
                            SmolStr::new_static("entryUri")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("content"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(1000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("entryUri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("ogp"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("url")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("height"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("width"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod comment_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 EntryUri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Content = Unset;
        type EntryUri = 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 EntryUri = St::EntryUri;
    }
    ///State transition - sets the `entry_uri` field to Set
    pub struct SetEntryUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEntryUri<St> {}
    impl<St: State> State for SetEntryUri<St> {
        type Content = St::Content;
        type EntryUri = Set<members::entry_uri>;
    }
    /// 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 `entry_uri` field
        pub struct entry_uri(());
    }
}

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

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

impl<S: BosStr> Comment<S> {
    /// Create a new builder for this type
    pub fn builder() -> CommentBuilder<comment_state::Empty, S> {
        CommentBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> CommentBuilder<St, S>
where
    St: comment_state::State,
    St::EntryUri: comment_state::IsUnset,
{
    /// Set the `entryUri` field (required)
    pub fn entry_uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> CommentBuilder<comment_state::SetEntryUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        CommentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CommentBuilder<St, S>
where
    St: comment_state::State,
    St::Content: comment_state::IsSet,
    St::EntryUri: comment_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Comment<S> {
        Comment {
            content: self._fields.0.unwrap(),
            entry_uri: 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>>) -> Comment<S> {
        Comment {
            content: self._fields.0.unwrap(),
            entry_uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> Ogp<S> {
    /// Create a new builder for this type
    pub fn builder() -> OgpBuilder<ogp_state::Empty, S> {
        OgpBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> OgpBuilder<St, S>
where
    St: ogp_state::State,
    St::Url: ogp_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> OgpBuilder<ogp_state::SetUrl<St>, S> {
        self._fields.1 = Option::Some(value.into());
        OgpBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: ogp_state::State, S: BosStr> OgpBuilder<St, S> {
    /// Set the `width` field (optional)
    pub fn width(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `width` field to an Option value (optional)
    pub fn maybe_width(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> OgpBuilder<St, S>
where
    St: ogp_state::State,
    St::Url: ogp_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Ogp<S> {
        Ogp {
            height: self._fields.0,
            url: self._fields.1.unwrap(),
            width: self._fields.2,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Ogp<S> {
        Ogp {
            height: self._fields.0,
            url: self._fields.1.unwrap(),
            width: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}