#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{AtUri, Datetime};
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 Event<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub end_date: Option<Datetime>,
pub start_date: Datetime,
pub title: 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 EventOutput<S: BosStr = DefaultStr> {
pub uri: AtUri<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
pub struct EventResponse;
impl jacquard_common::xrpc::XrpcResp for EventResponse {
const NSID: &'static str = "st.lifepo.event";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = EventOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Event<S> {
const NSID: &'static str = "st.lifepo.event";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Response = EventResponse;
}
pub struct EventRequest;
impl jacquard_common::xrpc::XrpcEndpoint for EventRequest {
const PATH: &'static str = "/xrpc/st.lifepo.event";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Request<S: BosStr> = Event<S>;
type Response = EventResponse;
}
pub mod event_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 Title;
type StartDate;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type StartDate = Unset;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type Title = Set<members::title>;
type StartDate = St::StartDate;
}
pub struct SetStartDate<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetStartDate<St> {}
impl<St: State> State for SetStartDate<St> {
type Title = St::Title;
type StartDate = Set<members::start_date>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct start_date(());
}
}
pub struct EventBuilder<S: BosStr, St: event_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<Datetime>, Option<Datetime>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Event<S> {
pub fn new() -> EventBuilder<S, event_state::Empty> {
EventBuilder::new()
}
}
impl<S: BosStr> EventBuilder<S, event_state::Empty> {
pub fn new() -> Self {
EventBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: event_state::State> EventBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: event_state::State> EventBuilder<S, St> {
pub fn end_date(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_end_date(mut self, value: Option<Datetime>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::StartDate: event_state::IsUnset,
{
pub fn start_date(
mut self,
value: impl Into<Datetime>,
) -> EventBuilder<S, event_state::SetStartDate<St>> {
self._fields.2 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Title: event_state::IsUnset,
{
pub fn title(mut self, value: impl Into<S>) -> EventBuilder<S, event_state::SetTitle<St>> {
self._fields.3 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Title: event_state::IsSet,
St::StartDate: event_state::IsSet,
{
pub fn build(self) -> Event<S> {
Event {
description: self._fields.0,
end_date: self._fields.1,
start_date: self._fields.2.unwrap(),
title: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Event<S> {
Event {
description: self._fields.0,
end_date: self._fields.1,
start_date: self._fields.2.unwrap(),
title: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}