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

use jacquard_common::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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};
/// A physical location in the form of a street address.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Address<'a> {
    ///The ISO 3166 country code. Preferably the 2-letter code.
    #[serde(borrow)]
    pub country: CowStr<'a>,
    ///The locality of the region. For example, a city in the USA.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub locality: Option<CowStr<'a>>,
    ///The name of the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    ///The postal code of the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub postal_code: Option<CowStr<'a>>,
    ///The administrative region of the country. For example, a state in the USA.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub region: Option<CowStr<'a>>,
    ///The street address.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub street: Option<CowStr<'a>>,
}

impl<'a> LexiconSchema for Address<'a> {
    fn nsid() -> &'static str {
        "community.lexicon.location.address"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_community_lexicon_location_address()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.country;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("country"),
                    max: 10usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.country;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 2usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("country"),
                    min: 2usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_community_lexicon_location_address() -> 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("community.lexicon.location.address"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A physical location in the form of a street address.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("country")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("country"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The ISO 3166 country code. Preferably the 2-letter code.",
                                    ),
                                ),
                                min_length: Some(2usize),
                                max_length: Some(10usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("locality"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The locality of the region. For example, a city in the USA.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The name of the location."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("postalCode"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The postal code of the location."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("region"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The administrative region of the country. For example, a state in the USA.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("street"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The street address."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}