// @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, 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::string::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};
use crate::blog_pckt::mark::link;
/// Link attributes

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LinkAttrs<S: BosStr = DefaultStr> {
    ///The URL destination of the hyperlink
    pub href: UriValue<S>,
    ///Defines the relationship between the current document and the linked resource (e.g., nofollow, noopener)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rel: Option<S>,
    ///Specifies where to open the linked document (e.g., _blank, _self)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target: Option<S>,
    ///Additional information about the link, typically shown as a tooltip on hover
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: 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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Link<S: BosStr = DefaultStr> {
    ///Link attributes that define the hyperlink behavior and destination
    pub attrs: link::LinkAttrs<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for LinkAttrs<S> {
    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<S: BosStr> LexiconSchema for Link<S> {
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHref<St> {}
    impl<St: State> State for SetHref<St> {
        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<St: link_attrs_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<UriValue<S>>, Option<S>, Option<S>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

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

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

impl<St, S: BosStr> LinkAttrsBuilder<St, S>
where
    St: link_attrs_state::State,
    St::Href: link_attrs_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> LinkAttrs<S> {
        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<SmolStr, Data<S>>,
    ) -> LinkAttrs<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAttrs<St> {}
    impl<St: State> State for SetAttrs<St> {
        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<St: link_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<link::LinkAttrs<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> LinkBuilder<St, S>
where
    St: link_state::State,
    St::Attrs: link_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Link<S> {
        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<SmolStr, Data<S>>) -> Link<S> {
        Link {
            attrs: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}