#[allow(unused_imports)]
use alloc::collections::BTreeMap;
use crate::at_inlay::Response;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::IntoStatic;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Grid<S: BosStr = DefaultStr> {
pub children: Data<S>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_grid_columns")]
pub columns: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub gap: Option<GridGap<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GridGap<S: BosStr = DefaultStr> {
None,
Small,
Medium,
Large,
Other(S),
}
impl<S: BosStr> GridGap<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(),
}
}
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 GridGap<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for GridGap<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for GridGap<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 GridGap<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 GridGap<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for GridGap<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = GridGap<S::Output>;
fn into_static(self) -> Self::Output {
match self {
GridGap::None => GridGap::None,
GridGap::Small => GridGap::Small,
GridGap::Medium => GridGap::Medium,
GridGap::Large => GridGap::Large,
GridGap::Other(v) => GridGap::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct GridOutput<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>>>,
}
pub struct GridResponse;
impl jacquard_common::xrpc::XrpcResp for GridResponse {
const NSID: &'static str = "org.atsui.Grid";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = GridOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Grid<S> {
const NSID: &'static str = "org.atsui.Grid";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Response = GridResponse;
}
pub struct GridRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GridRequest {
const PATH: &'static str = "/xrpc/org.atsui.Grid";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Request<S: BosStr> = Grid<S>;
type Response = GridResponse;
}
fn _default_grid_columns() -> Option<i64> {
Some(3i64)
}
pub mod grid_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Children;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Children = Unset;
}
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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct children(());
}
}
pub struct GridBuilder<S: BosStr, St: grid_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Data<S>>, Option<i64>, Option<GridGap<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Grid<S> {
pub fn new() -> GridBuilder<S, grid_state::Empty> {
GridBuilder::new()
}
}
impl<S: BosStr> GridBuilder<S, grid_state::Empty> {
pub fn new() -> Self {
GridBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GridBuilder<S, St>
where
St: grid_state::State,
St::Children: grid_state::IsUnset,
{
pub fn children(
mut self,
value: impl Into<Data<S>>,
) -> GridBuilder<S, grid_state::SetChildren<St>> {
self._fields.0 = Option::Some(value.into());
GridBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: grid_state::State> GridBuilder<S, St> {
pub fn columns(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_columns(mut self, value: Option<i64>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: grid_state::State> GridBuilder<S, St> {
pub fn gap(mut self, value: impl Into<Option<GridGap<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_gap(mut self, value: Option<GridGap<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> GridBuilder<S, St>
where
St: grid_state::State,
St::Children: grid_state::IsSet,
{
pub fn build(self) -> Grid<S> {
Grid {
children: self._fields.0.unwrap(),
columns: self._fields.1.or_else(|| Some(3i64)),
gap: self._fields.2,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Grid<S> {
Grid {
children: self._fields.0.unwrap(),
columns: self._fields.1.or_else(|| Some(3i64)),
gap: self._fields.2,
extra_data: Some(extra_data),
}
}
}