// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.atsui.Row
//
// 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 Row<S: BosStr = DefaultStr> {
    ///Cross-axis (vertical) alignment of children.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub align: Option<RowAlign<S>>,
    pub children: Data<S>,
    ///Space between children.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub gap: Option<RowGap<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<RowJustify<S>>,
    ///Whether the container has an opaque background.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub opaque: 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 (vertical) alignment of children.

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

impl<S: BosStr> RowAlign<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 RowAlign<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

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

impl<S: BosStr> Serialize for RowAlign<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 RowAlign<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 RowAlign<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

/// Space between children.

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

impl<S: BosStr> RowGap<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 RowGap<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

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

impl<S: BosStr> Serialize for RowGap<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 RowGap<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 RowGap<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

/// Main-axis distribution of children.

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

impl<S: BosStr> RowJustify<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 RowJustify<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

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

impl<S: BosStr> Serialize for RowJustify<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 RowJustify<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 RowJustify<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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


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

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

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

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

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

pub mod row_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 RowBuilder<St: row_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<RowAlign<S>>,
        Option<Data<S>>,
        Option<RowGap<S>>,
        Option<bool>,
        Option<RowJustify<S>>,
        Option<bool>,
        Option<bool>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Row<S> {
    /// Create a new builder for this type
    pub fn builder() -> RowBuilder<row_state::Empty, S> {
        RowBuilder::builder()
    }
}

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

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

impl<St: row_state::State, S: BosStr> RowBuilder<St, S> {
    /// Set the `align` field (optional)
    pub fn align(mut self, value: impl Into<Option<RowAlign<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<RowAlign<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: row_state::State, S: BosStr> RowBuilder<St, S> {
    /// Set the `gap` field (optional)
    pub fn gap(mut self, value: impl Into<Option<RowGap<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<RowGap<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: row_state::State, S: BosStr> RowBuilder<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: row_state::State, S: BosStr> RowBuilder<St, S> {
    /// Set the `justify` field (optional)
    pub fn justify(mut self, value: impl Into<Option<RowJustify<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<RowJustify<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<St, S: BosStr> RowBuilder<St, S>
where
    St: row_state::State,
    St::Children: row_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Row<S> {
        Row {
            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,
            sticky: self._fields.6,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Row<S> {
        Row {
            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,
            sticky: self._fields.6,
            extra_data: Some(extra_data),
        }
    }
}