// @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, 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::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::at_inlay::Element;
use crate::at_inlay::Response;
use crate::org_atsui::tabs;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Tabs<S: BosStr = DefaultStr> {
    ///Tabs to display.
    pub items: Vec<tabs::Tab<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 TabsOutput<S: BosStr = DefaultStr> {
    #[serde(flatten)]
    pub value: Response<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 Tab<S: BosStr = DefaultStr> {
    ///Element to render as tab content.
    pub content: Element<S>,
    ///Stable key that identifies the tab among its siblings.
    pub key: S,
    ///Display label for the tab.
    pub label: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `org.atsui.Tabs` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `TabsOutput<S>` for this endpoint.*/
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<S: BosStr> = TabsOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

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

/** Endpoint marker for the `org.atsui.Tabs` procedure.

Path: `/xrpc/org.atsui.Tabs`. The request payload type is `Tabs<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
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<S: BosStr> = Tabs<S>;
    type Response = TabsResponse;
}

impl<S: BosStr> LexiconSchema for Tab<S> {
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetItems<St> {}
    impl<St: State> State for SetItems<St> {
        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<St: tabs_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Vec<tabs::Tab<S>>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> TabsBuilder<St, S>
where
    St: tabs_state::State,
    St::Items: tabs_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Tabs<S> {
        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<SmolStr, Data<S>>) -> Tabs<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetContent<St> {}
    impl<St: State> State for SetContent<St> {
        type Content = Set<members::content>;
        type Key = St::Key;
        type Label = St::Label;
    }
    ///State transition - sets the `key` field to Set
    pub struct SetKey<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetKey<St> {}
    impl<St: State> State for SetKey<St> {
        type Content = St::Content;
        type Key = Set<members::key>;
        type Label = St::Label;
    }
    ///State transition - sets the `label` field to Set
    pub struct SetLabel<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLabel<St> {}
    impl<St: State> State for SetLabel<St> {
        type Content = St::Content;
        type Key = St::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<St: tab_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Element<S>>, Option<S>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

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

impl<St, S: BosStr> TabBuilder<St, S>
where
    St: tab_state::State,
    St::Content: tab_state::IsSet,
    St::Key: tab_state::IsSet,
    St::Label: tab_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Tab<S> {
        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<SmolStr, Data<S>>) -> Tab<S> {
        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()
    }
}