#[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::string::{Did, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SetStats<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub last_pull: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_push: Option<Datetime>,
pub owner_did: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pull_count: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub push_count: Option<i64>,
pub repository: 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 SetStatsOutput<S: BosStr = DefaultStr> {
pub success: bool,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic
)]
#[serde(tag = "error", content = "message")]
pub enum SetStatsError {
#[serde(rename = "InvalidOwner")]
InvalidOwner(Option<SmolStr>),
#[serde(rename = "InvalidRepository")]
InvalidRepository(Option<SmolStr>),
#[serde(untagged)]
Other { error: SmolStr, message: Option<SmolStr> },
}
impl core::fmt::Display for SetStatsError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidOwner(msg) => {
write!(f, "InvalidOwner")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::InvalidRepository(msg) => {
write!(f, "InvalidRepository")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Other { error, message } => {
write!(f, "{}", error)?;
if let Some(msg) = message {
write!(f, ": {}", msg)?;
}
Ok(())
}
}
}
}
pub struct SetStatsResponse;
impl jacquard_common::xrpc::XrpcResp for SetStatsResponse {
const NSID: &'static str = "io.atcr.hold.setStats";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = SetStatsOutput<S>;
type Err = SetStatsError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for SetStats<S> {
const NSID: &'static str = "io.atcr.hold.setStats";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = SetStatsResponse;
}
pub struct SetStatsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for SetStatsRequest {
const PATH: &'static str = "/xrpc/io.atcr.hold.setStats";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = SetStats<S>;
type Response = SetStatsResponse;
}
pub mod set_stats_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Repository;
type OwnerDid;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Repository = Unset;
type OwnerDid = Unset;
}
pub struct SetRepository<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRepository<St> {}
impl<St: State> State for SetRepository<St> {
type Repository = Set<members::repository>;
type OwnerDid = St::OwnerDid;
}
pub struct SetOwnerDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetOwnerDid<St> {}
impl<St: State> State for SetOwnerDid<St> {
type Repository = St::Repository;
type OwnerDid = Set<members::owner_did>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct repository(());
pub struct owner_did(());
}
}
pub struct SetStatsBuilder<S: BosStr, St: set_stats_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<Datetime>,
Option<Did<S>>,
Option<i64>,
Option<i64>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> SetStats<S> {
pub fn new() -> SetStatsBuilder<S, set_stats_state::Empty> {
SetStatsBuilder::new()
}
}
impl<S: BosStr> SetStatsBuilder<S, set_stats_state::Empty> {
pub fn new() -> Self {
SetStatsBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: set_stats_state::State> SetStatsBuilder<S, St> {
pub fn last_pull(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_last_pull(mut self, value: Option<Datetime>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: set_stats_state::State> SetStatsBuilder<S, St> {
pub fn last_push(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_last_push(mut self, value: Option<Datetime>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> SetStatsBuilder<S, St>
where
St: set_stats_state::State,
St::OwnerDid: set_stats_state::IsUnset,
{
pub fn owner_did(
mut self,
value: impl Into<Did<S>>,
) -> SetStatsBuilder<S, set_stats_state::SetOwnerDid<St>> {
self._fields.2 = Option::Some(value.into());
SetStatsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: set_stats_state::State> SetStatsBuilder<S, St> {
pub fn pull_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_pull_count(mut self, value: Option<i64>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: set_stats_state::State> SetStatsBuilder<S, St> {
pub fn push_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_push_count(mut self, value: Option<i64>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> SetStatsBuilder<S, St>
where
St: set_stats_state::State,
St::Repository: set_stats_state::IsUnset,
{
pub fn repository(
mut self,
value: impl Into<S>,
) -> SetStatsBuilder<S, set_stats_state::SetRepository<St>> {
self._fields.5 = Option::Some(value.into());
SetStatsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SetStatsBuilder<S, St>
where
St: set_stats_state::State,
St::Repository: set_stats_state::IsSet,
St::OwnerDid: set_stats_state::IsSet,
{
pub fn build(self) -> SetStats<S> {
SetStats {
last_pull: self._fields.0,
last_push: self._fields.1,
owner_did: self._fields.2.unwrap(),
pull_count: self._fields.3,
push_count: self._fields.4,
repository: self._fields.5.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> SetStats<S> {
SetStats {
last_pull: self._fields.0,
last_push: self._fields.1,
owner_did: self._fields.2.unwrap(),
pull_count: self._fields.3,
push_count: self._fields.4,
repository: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}