#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::{AtUri, Datetime};
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Event<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub end_date: Option<Datetime>,
pub start_date: Datetime,
#[serde(borrow)]
pub title: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EventOutput<'a> {
#[serde(borrow)]
pub uri: AtUri<'a>,
}
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<'de> = EventOutput<'de>;
type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for Event<'a> {
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<'de> = Event<'de>;
type Response = EventResponse;
}
pub mod event_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 Title;
type StartDate;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type StartDate = Unset;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type Title = Set<members::title>;
type StartDate = S::StartDate;
}
pub struct SetStartDate<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetStartDate<S> {}
impl<S: State> State for SetStartDate<S> {
type Title = S::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<'a, S: event_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Datetime>,
Option<Datetime>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Event<'a> {
pub fn new() -> EventBuilder<'a, event_state::Empty> {
EventBuilder::new()
}
}
impl<'a> EventBuilder<'a, event_state::Empty> {
pub fn new() -> Self {
EventBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: event_state::State> EventBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: event_state::State> EventBuilder<'a, S> {
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<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::StartDate: event_state::IsUnset,
{
pub fn start_date(
mut self,
value: impl Into<Datetime>,
) -> EventBuilder<'a, event_state::SetStartDate<S>> {
self._fields.2 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Title: event_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> EventBuilder<'a, event_state::SetTitle<S>> {
self._fields.3 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Title: event_state::IsSet,
S::StartDate: event_state::IsSet,
{
pub fn build(self) -> Event<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Event<'a> {
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),
}
}
}