#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::{Did, Datetime};
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SetStats<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub last_pull: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_push: Option<Datetime>,
#[serde(borrow)]
pub owner_did: Did<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pull_count: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub push_count: Option<i64>,
#[serde(borrow)]
pub repository: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SetStatsOutput<'a> {
pub success: bool,
}
#[open_union]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic,
IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum SetStatsError<'a> {
#[serde(rename = "InvalidOwner")]
InvalidOwner(Option<CowStr<'a>>),
#[serde(rename = "InvalidRepository")]
InvalidRepository(Option<CowStr<'a>>),
}
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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
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<'de> = SetStatsOutput<'de>;
type Err<'de> = SetStatsError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for SetStats<'a> {
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<'de> = SetStats<'de>;
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<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRepository<S> {}
impl<S: State> State for SetRepository<S> {
type Repository = Set<members::repository>;
type OwnerDid = S::OwnerDid;
}
pub struct SetOwnerDid<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetOwnerDid<S> {}
impl<S: State> State for SetOwnerDid<S> {
type Repository = S::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<'a, S: set_stats_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<Datetime>,
Option<Did<'a>>,
Option<i64>,
Option<i64>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> SetStats<'a> {
pub fn new() -> SetStatsBuilder<'a, set_stats_state::Empty> {
SetStatsBuilder::new()
}
}
impl<'a> SetStatsBuilder<'a, set_stats_state::Empty> {
pub fn new() -> Self {
SetStatsBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: set_stats_state::State> SetStatsBuilder<'a, S> {
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<'a, S: set_stats_state::State> SetStatsBuilder<'a, S> {
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<'a, S> SetStatsBuilder<'a, S>
where
S: set_stats_state::State,
S::OwnerDid: set_stats_state::IsUnset,
{
pub fn owner_did(
mut self,
value: impl Into<Did<'a>>,
) -> SetStatsBuilder<'a, set_stats_state::SetOwnerDid<S>> {
self._fields.2 = Option::Some(value.into());
SetStatsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: set_stats_state::State> SetStatsBuilder<'a, S> {
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<'a, S: set_stats_state::State> SetStatsBuilder<'a, S> {
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<'a, S> SetStatsBuilder<'a, S>
where
S: set_stats_state::State,
S::Repository: set_stats_state::IsUnset,
{
pub fn repository(
mut self,
value: impl Into<CowStr<'a>>,
) -> SetStatsBuilder<'a, set_stats_state::SetRepository<S>> {
self._fields.5 = Option::Some(value.into());
SetStatsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SetStatsBuilder<'a, S>
where
S: set_stats_state::State,
S::Repository: set_stats_state::IsSet,
S::OwnerDid: set_stats_state::IsSet,
{
pub fn build(self) -> SetStats<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> SetStats<'a> {
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),
}
}
}