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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Website<'a> {
    ///A brief description of the website or page
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    ///URL of the preview image
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub preview_image: Option<UriValue<'a>>,
    ///The URL of the website
    #[serde(borrow)]
    pub src: UriValue<'a>,
    ///The title of the website or page
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub title: Option<CowStr<'a>>,
}

impl<'a> LexiconSchema for Website<'a> {
    fn nsid() -> &'static str {
        "blog.pckt.block.website"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blog_pckt_block_website()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

impl<'a> Website<'a> {
    /// Create a new builder for this type
    pub fn new() -> WebsiteBuilder<'a, website_state::Empty> {
        WebsiteBuilder::new()
    }
}

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

impl<'a, S: website_state::State> WebsiteBuilder<'a, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: website_state::State> WebsiteBuilder<'a, S> {
    /// Set the `previewImage` field (optional)
    pub fn preview_image(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `previewImage` field to an Option value (optional)
    pub fn maybe_preview_image(mut self, value: Option<UriValue<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> WebsiteBuilder<'a, S>
where
    S: website_state::State,
    S::Src: website_state::IsUnset,
{
    /// Set the `src` field (required)
    pub fn src(
        mut self,
        value: impl Into<UriValue<'a>>,
    ) -> WebsiteBuilder<'a, website_state::SetSrc<S>> {
        self._fields.2 = Option::Some(value.into());
        WebsiteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: website_state::State> WebsiteBuilder<'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> WebsiteBuilder<'a, S>
where
    S: website_state::State,
    S::Src: website_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Website<'a> {
        Website {
            description: self._fields.0,
            preview_image: self._fields.1,
            src: self._fields.2.unwrap(),
            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>,
        >,
    ) -> Website<'a> {
        Website {
            description: self._fields.0,
            preview_image: self._fields.1,
            src: self._fields.2.unwrap(),
            title: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_blog_pckt_block_website() -> 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.block.website"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("src")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "A brief description of the website or page",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("previewImage"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URL of the preview image"),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("src"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The URL of the website"),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The title of the website or page"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}