// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.atsui.Stack
//
// 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};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::at_inlay::Response;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Stack<S: BosStr = DefaultStr> {
    ///Cross-axis alignment of children.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub align: Option<StackAlign<S>>,
    pub children: Data<S>,
    ///Space between children.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub gap: Option<StackGap<S>>,
    ///Whether this container has inset padding. The theme controls the amount.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inset: Option<bool>,
    ///Main-axis distribution of children.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub justify: Option<StackJustify<S>>,
    ///Whether the container has an opaque background.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub opaque: Option<bool>,
    ///Whether to show a visual separator between children.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub separator: Option<bool>,
    ///Whether the container sticks to the top of the scroll area.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sticky: Option<bool>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Cross-axis alignment of children.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StackAlign<S: BosStr = DefaultStr> {
    Start,
    Center,
    End,
    Stretch,
    Other(S),
}

impl<S: BosStr> StackAlign<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Start => "start",
            Self::Center => "center",
            Self::End => "end",
            Self::Stretch => "stretch",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "start" => Self::Start,
            "center" => Self::Center,
            "end" => Self::End,
            "stretch" => Self::Stretch,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for StackAlign<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for StackAlign<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for StackAlign<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for StackAlign<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for StackAlign<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for StackAlign<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = StackAlign<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            StackAlign::Start => StackAlign::Start,
            StackAlign::Center => StackAlign::Center,
            StackAlign::End => StackAlign::End,
            StackAlign::Stretch => StackAlign::Stretch,
            StackAlign::Other(v) => StackAlign::Other(v.into_static()),
        }
    }
}

/// Space between children.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StackGap<S: BosStr = DefaultStr> {
    None,
    Small,
    Medium,
    Large,
    Other(S),
}

impl<S: BosStr> StackGap<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::None => "none",
            Self::Small => "small",
            Self::Medium => "medium",
            Self::Large => "large",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "none" => Self::None,
            "small" => Self::Small,
            "medium" => Self::Medium,
            "large" => Self::Large,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for StackGap<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for StackGap<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for StackGap<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for StackGap<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for StackGap<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for StackGap<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = StackGap<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            StackGap::None => StackGap::None,
            StackGap::Small => StackGap::Small,
            StackGap::Medium => StackGap::Medium,
            StackGap::Large => StackGap::Large,
            StackGap::Other(v) => StackGap::Other(v.into_static()),
        }
    }
}

/// Main-axis distribution of children.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StackJustify<S: BosStr = DefaultStr> {
    Start,
    Center,
    End,
    Between,
    Other(S),
}

impl<S: BosStr> StackJustify<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Start => "start",
            Self::Center => "center",
            Self::End => "end",
            Self::Between => "between",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "start" => Self::Start,
            "center" => Self::Center,
            "end" => Self::End,
            "between" => Self::Between,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for StackJustify<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for StackJustify<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for StackJustify<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for StackJustify<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for StackJustify<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for StackJustify<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = StackJustify<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            StackJustify::Start => StackJustify::Start,
            StackJustify::Center => StackJustify::Center,
            StackJustify::End => StackJustify::End,
            StackJustify::Between => StackJustify::Between,
            StackJustify::Other(v) => StackJustify::Other(v.into_static()),
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct StackOutput<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>>>,
}

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

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `StackOutput<S>` for this endpoint.*/
pub struct StackResponse;
impl jacquard_common::xrpc::XrpcResp for StackResponse {
    const NSID: &'static str = "org.atsui.Stack";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = StackOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

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

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

Path: `/xrpc/org.atsui.Stack`. The request payload type is `Stack<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct StackRequest;
impl jacquard_common::xrpc::XrpcEndpoint for StackRequest {
    const PATH: &'static str = "/xrpc/org.atsui.Stack";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = Stack<S>;
    type Response = StackResponse;
}

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

/// Builder for constructing an instance of this type.
pub struct StackBuilder<St: stack_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<StackAlign<S>>,
        Option<Data<S>>,
        Option<StackGap<S>>,
        Option<bool>,
        Option<StackJustify<S>>,
        Option<bool>,
        Option<bool>,
        Option<bool>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Stack<S> {
    /// Create a new builder for this type
    pub fn builder() -> StackBuilder<stack_state::Empty, S> {
        StackBuilder::builder()
    }
}

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

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

impl<St: stack_state::State, S: BosStr> StackBuilder<St, S> {
    /// Set the `align` field (optional)
    pub fn align(mut self, value: impl Into<Option<StackAlign<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `align` field to an Option value (optional)
    pub fn maybe_align(mut self, value: Option<StackAlign<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> StackBuilder<St, S>
where
    St: stack_state::State,
    St::Children: stack_state::IsUnset,
{
    /// Set the `children` field (required)
    pub fn children(
        mut self,
        value: impl Into<Data<S>>,
    ) -> StackBuilder<stack_state::SetChildren<St>, S> {
        self._fields.1 = Option::Some(value.into());
        StackBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St: stack_state::State, S: BosStr> StackBuilder<St, S> {
    /// Set the `justify` field (optional)
    pub fn justify(mut self, value: impl Into<Option<StackJustify<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `justify` field to an Option value (optional)
    pub fn maybe_justify(mut self, value: Option<StackJustify<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: stack_state::State, S: BosStr> StackBuilder<St, S> {
    /// Set the `opaque` field (optional)
    pub fn opaque(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `opaque` field to an Option value (optional)
    pub fn maybe_opaque(mut self, value: Option<bool>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: stack_state::State, S: BosStr> StackBuilder<St, S> {
    /// Set the `separator` field (optional)
    pub fn separator(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `separator` field to an Option value (optional)
    pub fn maybe_separator(mut self, value: Option<bool>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: stack_state::State, S: BosStr> StackBuilder<St, S> {
    /// Set the `sticky` field (optional)
    pub fn sticky(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `sticky` field to an Option value (optional)
    pub fn maybe_sticky(mut self, value: Option<bool>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St, S: BosStr> StackBuilder<St, S>
where
    St: stack_state::State,
    St::Children: stack_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Stack<S> {
        Stack {
            align: self._fields.0,
            children: self._fields.1.unwrap(),
            gap: self._fields.2,
            inset: self._fields.3,
            justify: self._fields.4,
            opaque: self._fields.5,
            separator: self._fields.6,
            sticky: self._fields.7,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Stack<S> {
        Stack {
            align: self._fields.0,
            children: self._fields.1.unwrap(),
            gap: self._fields.2,
            inset: self._fields.3,
            justify: self._fields.4,
            opaque: self._fields.5,
            separator: self._fields.6,
            sticky: self._fields.7,
            extra_data: Some(extra_data),
        }
    }
}