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

//! Generated bindings for the `bond.biblio` Lexicon namespace/module.
pub mod book;
pub mod list;
pub mod stamp;


#[allow(unused_imports)]
use alloc::collections::BTreeMap;
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::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};
/// A required book for a reading list, specified by title and authors for fuzzy matching

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct BookRequirement<S: BosStr = DefaultStr> {
    ///Author name(s), tab-separated for multiple
    pub authors: S,
    pub title: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for BookRequirement<S> {
    fn nsid() -> &'static str {
        "bond.biblio.defs"
    }
    fn def_name() -> &'static str {
        "bookRequirement"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_bond_biblio_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.authors;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("authors"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.authors;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 200usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("authors"),
                        max: 200usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.title;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.title;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 200usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("title"),
                        max: 200usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

fn lexicon_doc_bond_biblio_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("bond.biblio.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("bookRequirement"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A required book for a reading list, specified by title and authors for fuzzy matching",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("title"), SmolStr::new_static("authors")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("authors"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Author name(s), tab-separated for multiple",
                                    ),
                                ),
                                max_length: Some(500usize),
                                max_graphemes: Some(200usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(500usize),
                                max_graphemes: Some(200usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}