// @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;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::at_inlay::Response;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Stack<'a> {
    ///Cross-axis alignment of children.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub align: Option<StackAlign<'a>>,
    #[serde(borrow)]
    pub children: Data<'a>,
    ///Space between children.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub gap: Option<StackGap<'a>>,
    ///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")]
    #[serde(borrow)]
    pub justify: Option<StackJustify<'a>>,
    ///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>,
}

/// Cross-axis alignment of children.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StackAlign<'a> {
    Start,
    Center,
    End,
    Stretch,
    Other(CowStr<'a>),
}

impl<'a> StackAlign<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for StackAlign<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "start" => Self::Start,
            "center" => Self::Center,
            "end" => Self::End,
            "stretch" => Self::Stretch,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for StackAlign<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "start" => Self::Start,
            "center" => Self::Center,
            "end" => Self::End,
            "stretch" => Self::Stretch,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for StackAlign<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for StackAlign<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for StackAlign<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for StackAlign<'_> {
    type Output = StackAlign<'static>;
    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<'a> {
    None,
    Small,
    Medium,
    Large,
    Other(CowStr<'a>),
}

impl<'a> StackGap<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for StackGap<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "none" => Self::None,
            "small" => Self::Small,
            "medium" => Self::Medium,
            "large" => Self::Large,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for StackGap<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "none" => Self::None,
            "small" => Self::Small,
            "medium" => Self::Medium,
            "large" => Self::Large,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for StackGap<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for StackGap<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for StackGap<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for StackGap<'_> {
    type Output = StackGap<'static>;
    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<'a> {
    Start,
    Center,
    End,
    Between,
    Other(CowStr<'a>),
}

impl<'a> StackJustify<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for StackJustify<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "start" => Self::Start,
            "center" => Self::Center,
            "end" => Self::End,
            "between" => Self::Between,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for StackJustify<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "start" => Self::Start,
            "center" => Self::Center,
            "end" => Self::End,
            "between" => Self::Between,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for StackJustify<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for StackJustify<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for StackJustify<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for StackJustify<'_> {
    type Output = StackJustify<'static>;
    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()),
        }
    }
}


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

/// Response type for org.atsui.Stack
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<'de> = StackOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for org.atsui.Stack
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<'de> = Stack<'de>;
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetChildren<S> {}
    impl<S: State> State for SetChildren<S> {
        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<'a, S: stack_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<StackAlign<'a>>,
        Option<Data<'a>>,
        Option<StackGap<'a>>,
        Option<bool>,
        Option<StackJustify<'a>>,
        Option<bool>,
        Option<bool>,
        Option<bool>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: stack_state::State> StackBuilder<'a, S> {
    /// Set the `align` field (optional)
    pub fn align(mut self, value: impl Into<Option<StackAlign<'a>>>) -> 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<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<'a, S: stack_state::State> StackBuilder<'a, S> {
    /// Set the `gap` field (optional)
    pub fn gap(mut self, value: impl Into<Option<StackGap<'a>>>) -> 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<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: stack_state::State> StackBuilder<'a, 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<'a, S: stack_state::State> StackBuilder<'a, S> {
    /// Set the `justify` field (optional)
    pub fn justify(mut self, value: impl Into<Option<StackJustify<'a>>>) -> 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<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: stack_state::State> StackBuilder<'a, 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<'a, S: stack_state::State> StackBuilder<'a, 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<'a, S: stack_state::State> StackBuilder<'a, 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<'a, S> StackBuilder<'a, S>
where
    S: stack_state::State,
    S::Children: stack_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Stack<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Stack<'a> {
        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),
        }
    }
}