// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: blog.pckt.mark.link
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::UriValue;
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::blog_pckt::mark::link;
/// Link attributes

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LinkAttrs<'a> {
    ///The URL destination of the hyperlink
    #[serde(borrow)]
    pub href: UriValue<'a>,
    ///Defines the relationship between the current document and the linked resource (e.g., nofollow, noopener)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub rel: Option<CowStr<'a>>,
    ///Specifies where to open the linked document (e.g., _blank, _self)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub target: Option<CowStr<'a>>,
    ///Additional information about the link, typically shown as a tooltip on hover
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub title: Option<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Link<'a> {
    ///Link attributes that define the hyperlink behavior and destination
    #[serde(borrow)]
    pub attrs: link::LinkAttrs<'a>,
}

impl<'a> LexiconSchema for LinkAttrs<'a> {
    fn nsid() -> &'static str {
        "blog.pckt.mark.link"
    }
    fn def_name() -> &'static str {
        "linkAttrs"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blog_pckt_mark_link()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.href;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("href"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.rel {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("rel"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.target {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("target"),
                    max: 50usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref 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()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Link<'a> {
    fn nsid() -> &'static str {
        "blog.pckt.mark.link"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blog_pckt_mark_link()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

/// Builder for constructing an instance of this type
pub struct LinkAttrsBuilder<'a, S: link_attrs_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<UriValue<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> LinkAttrs<'a> {
    /// Create a new builder for this type
    pub fn new() -> LinkAttrsBuilder<'a, link_attrs_state::Empty> {
        LinkAttrsBuilder::new()
    }
}

impl<'a> LinkAttrsBuilder<'a, link_attrs_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        LinkAttrsBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> LinkAttrsBuilder<'a, S>
where
    S: link_attrs_state::State,
    S::Href: link_attrs_state::IsUnset,
{
    /// Set the `href` field (required)
    pub fn href(
        mut self,
        value: impl Into<UriValue<'a>>,
    ) -> LinkAttrsBuilder<'a, link_attrs_state::SetHref<S>> {
        self._fields.0 = Option::Some(value.into());
        LinkAttrsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: link_attrs_state::State> LinkAttrsBuilder<'a, S> {
    /// Set the `rel` field (optional)
    pub fn rel(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `rel` field to an Option value (optional)
    pub fn maybe_rel(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: link_attrs_state::State> LinkAttrsBuilder<'a, S> {
    /// Set the `target` field (optional)
    pub fn target(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `target` field to an Option value (optional)
    pub fn maybe_target(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: link_attrs_state::State> LinkAttrsBuilder<'a, S> {
    /// Set the `title` field (optional)
    pub fn title(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `title` field to an Option value (optional)
    pub fn maybe_title(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> LinkAttrsBuilder<'a, S>
where
    S: link_attrs_state::State,
    S::Href: link_attrs_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> LinkAttrs<'a> {
        LinkAttrs {
            href: self._fields.0.unwrap(),
            rel: self._fields.1,
            target: self._fields.2,
            title: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> LinkAttrs<'a> {
        LinkAttrs {
            href: self._fields.0.unwrap(),
            rel: self._fields.1,
            target: self._fields.2,
            title: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_blog_pckt_mark_link() -> 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("blog.pckt.mark.link"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("linkAttrs"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Link attributes")),
                    required: Some(vec![SmolStr::new_static("href")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("href"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The URL destination of the hyperlink"),
                                ),
                                format: Some(LexStringFormat::Uri),
                                max_length: Some(2000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rel"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Defines the relationship between the current document and the linked resource (e.g., nofollow, noopener)",
                                    ),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("target"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Specifies where to open the linked document (e.g., _blank, _self)",
                                    ),
                                ),
                                max_length: Some(50usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Additional information about the link, typically shown as a tooltip on hover",
                                    ),
                                ),
                                max_length: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("attrs")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("attrs"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#linkAttrs"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type
pub struct LinkBuilder<'a, S: link_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<link::LinkAttrs<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Link<'a> {
    /// Create a new builder for this type
    pub fn new() -> LinkBuilder<'a, link_state::Empty> {
        LinkBuilder::new()
    }
}

impl<'a> LinkBuilder<'a, link_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        LinkBuilder {
            _state: PhantomData,
            _fields: (None,),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> LinkBuilder<'a, S>
where
    S: link_state::State,
    S::Attrs: link_state::IsUnset,
{
    /// Set the `attrs` field (required)
    pub fn attrs(
        mut self,
        value: impl Into<link::LinkAttrs<'a>>,
    ) -> LinkBuilder<'a, link_state::SetAttrs<S>> {
        self._fields.0 = Option::Some(value.into());
        LinkBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> LinkBuilder<'a, S>
where
    S: link_state::State,
    S::Attrs: link_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Link<'a> {
        Link {
            attrs: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Link<'a> {
        Link {
            attrs: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}