// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.atsui.Tabs
//
// 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_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::at_inlay::Element;
use crate::at_inlay::Response;
use crate::org_atsui::tabs;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Tabs<'a> {
    ///Tabs to display.
    #[serde(borrow)]
    pub items: Vec<tabs::Tab<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TabsOutput<'a> {
    #[serde(flatten)]
    #[serde(borrow)]
    pub value: Response<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Tab<'a> {
    ///Element to render as tab content.
    #[serde(borrow)]
    pub content: Element<'a>,
    ///Stable key that identifies the tab among its siblings.
    #[serde(borrow)]
    pub key: CowStr<'a>,
    ///Display label for the tab.
    #[serde(borrow)]
    pub label: CowStr<'a>,
}

/// Response type for org.atsui.Tabs
pub struct TabsResponse;
impl jacquard_common::xrpc::XrpcResp for TabsResponse {
    const NSID: &'static str = "org.atsui.Tabs";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = TabsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for Tabs<'a> {
    const NSID: &'static str = "org.atsui.Tabs";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = TabsResponse;
}

/// Endpoint type for org.atsui.Tabs
pub struct TabsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for TabsRequest {
    const PATH: &'static str = "/xrpc/org.atsui.Tabs";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = Tabs<'de>;
    type Response = TabsResponse;
}

impl<'a> LexiconSchema for Tab<'a> {
    fn nsid() -> &'static str {
        "org.atsui.Tabs"
    }
    fn def_name() -> &'static str {
        "tab"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_atsui_Tabs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.key;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 64usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("key"),
                    max: 64usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.label;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("label"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

/// Builder for constructing an instance of this type
pub struct TabsBuilder<'a, S: tabs_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<tabs::Tab<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Tabs<'a> {
    /// Create a new builder for this type
    pub fn new() -> TabsBuilder<'a, tabs_state::Empty> {
        TabsBuilder::new()
    }
}

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

impl<'a, S> TabsBuilder<'a, S>
where
    S: tabs_state::State,
    S::Items: tabs_state::IsUnset,
{
    /// Set the `items` field (required)
    pub fn items(
        mut self,
        value: impl Into<Vec<tabs::Tab<'a>>>,
    ) -> TabsBuilder<'a, tabs_state::SetItems<S>> {
        self._fields.0 = Option::Some(value.into());
        TabsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> TabsBuilder<'a, S>
where
    S: tabs_state::State,
    S::Items: tabs_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Tabs<'a> {
        Tabs {
            items: 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>,
        >,
    ) -> Tabs<'a> {
        Tabs {
            items: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod tab_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 Content;
        type Key;
        type Label;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Content = Unset;
        type Key = Unset;
        type Label = Unset;
    }
    ///State transition - sets the `content` field to Set
    pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContent<S> {}
    impl<S: State> State for SetContent<S> {
        type Content = Set<members::content>;
        type Key = S::Key;
        type Label = S::Label;
    }
    ///State transition - sets the `key` field to Set
    pub struct SetKey<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetKey<S> {}
    impl<S: State> State for SetKey<S> {
        type Content = S::Content;
        type Key = Set<members::key>;
        type Label = S::Label;
    }
    ///State transition - sets the `label` field to Set
    pub struct SetLabel<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLabel<S> {}
    impl<S: State> State for SetLabel<S> {
        type Content = S::Content;
        type Key = S::Key;
        type Label = Set<members::label>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `content` field
        pub struct content(());
        ///Marker type for the `key` field
        pub struct key(());
        ///Marker type for the `label` field
        pub struct label(());
    }
}

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

impl<'a> Tab<'a> {
    /// Create a new builder for this type
    pub fn new() -> TabBuilder<'a, tab_state::Empty> {
        TabBuilder::new()
    }
}

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

impl<'a, S> TabBuilder<'a, S>
where
    S: tab_state::State,
    S::Content: tab_state::IsUnset,
{
    /// Set the `content` field (required)
    pub fn content(
        mut self,
        value: impl Into<Element<'a>>,
    ) -> TabBuilder<'a, tab_state::SetContent<S>> {
        self._fields.0 = Option::Some(value.into());
        TabBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> TabBuilder<'a, S>
where
    S: tab_state::State,
    S::Key: tab_state::IsUnset,
{
    /// Set the `key` field (required)
    pub fn key(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> TabBuilder<'a, tab_state::SetKey<S>> {
        self._fields.1 = Option::Some(value.into());
        TabBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> TabBuilder<'a, S>
where
    S: tab_state::State,
    S::Label: tab_state::IsUnset,
{
    /// Set the `label` field (required)
    pub fn label(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> TabBuilder<'a, tab_state::SetLabel<S>> {
        self._fields.2 = Option::Some(value.into());
        TabBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> TabBuilder<'a, S>
where
    S: tab_state::State,
    S::Content: tab_state::IsSet,
    S::Key: tab_state::IsSet,
    S::Label: tab_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Tab<'a> {
        Tab {
            content: self._fields.0.unwrap(),
            key: self._fields.1.unwrap(),
            label: self._fields.2.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>,
        >,
    ) -> Tab<'a> {
        Tab {
            content: self._fields.0.unwrap(),
            key: self._fields.1.unwrap(),
            label: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_atsui_Tabs() -> 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("org.atsui.Tabs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(vec![SmolStr::new_static("items")]),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("items"),
                                        LexObjectProperty::Array(LexArray {
                                            description: Some(CowStr::new_static("Tabs to display.")),
                                            items: LexArrayItem::Ref(LexRef {
                                                r#ref: CowStr::new_static("#tab"),
                                                ..Default::default()
                                            }),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("tab"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("key"), SmolStr::new_static("label"),
                            SmolStr::new_static("content")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("content"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("at.inlay.defs#element"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("key"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Stable key that identifies the tab among its siblings.",
                                    ),
                                ),
                                max_length: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("label"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Display label for the tab."),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}