// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: community.lexicon.calendar.getRSVP
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::{Did, AtUri};
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
use crate::community_lexicon::calendar::rsvp::Rsvp;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetRsvp<'a> {
    #[serde(borrow)]
    pub event: AtUri<'a>,
    #[serde(borrow)]
    pub identity: Did<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetRsvpOutput<'a> {
    ///CID of the RSVP record.
    #[serde(borrow)]
    pub cid: CowStr<'a>,
    ///The RSVP record.
    #[serde(borrow)]
    pub record: Rsvp<'a>,
    ///AT-URI of the RSVP record.
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}


#[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 GetRsvpError<'a> {
    #[serde(rename = "NotFound")]
    NotFound(Option<CowStr<'a>>),
}

impl core::fmt::Display for GetRsvpError<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::NotFound(msg) => {
                write!(f, "NotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

/// Response type for community.lexicon.calendar.getRSVP
pub struct GetRsvpResponse;
impl jacquard_common::xrpc::XrpcResp for GetRsvpResponse {
    const NSID: &'static str = "community.lexicon.calendar.getRSVP";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetRsvpOutput<'de>;
    type Err<'de> = GetRsvpError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetRsvp<'a> {
    const NSID: &'static str = "community.lexicon.calendar.getRSVP";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetRsvpResponse;
}

/// Endpoint type for community.lexicon.calendar.getRSVP
pub struct GetRsvpRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetRsvpRequest {
    const PATH: &'static str = "/xrpc/community.lexicon.calendar.getRSVP";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetRsvp<'de>;
    type Response = GetRsvpResponse;
}

pub mod get_rsvp_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Identity;
        type Event;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Identity = Unset;
        type Event = Unset;
    }
    ///State transition - sets the `identity` field to Set
    pub struct SetIdentity<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIdentity<S> {}
    impl<S: State> State for SetIdentity<S> {
        type Identity = Set<members::identity>;
        type Event = S::Event;
    }
    ///State transition - sets the `event` field to Set
    pub struct SetEvent<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEvent<S> {}
    impl<S: State> State for SetEvent<S> {
        type Identity = S::Identity;
        type Event = Set<members::event>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `identity` field
        pub struct identity(());
        ///Marker type for the `event` field
        pub struct event(());
    }
}

/// Builder for constructing an instance of this type
pub struct GetRsvpBuilder<'a, S: get_rsvp_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AtUri<'a>>, Option<Did<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> GetRsvp<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetRsvpBuilder<'a, get_rsvp_state::Empty> {
        GetRsvpBuilder::new()
    }
}

impl<'a> GetRsvpBuilder<'a, get_rsvp_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        GetRsvpBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> GetRsvpBuilder<'a, S>
where
    S: get_rsvp_state::State,
    S::Event: get_rsvp_state::IsUnset,
{
    /// Set the `event` field (required)
    pub fn event(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> GetRsvpBuilder<'a, get_rsvp_state::SetEvent<S>> {
        self._fields.0 = Option::Some(value.into());
        GetRsvpBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> GetRsvpBuilder<'a, S>
where
    S: get_rsvp_state::State,
    S::Identity: get_rsvp_state::IsUnset,
{
    /// Set the `identity` field (required)
    pub fn identity(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> GetRsvpBuilder<'a, get_rsvp_state::SetIdentity<S>> {
        self._fields.1 = Option::Some(value.into());
        GetRsvpBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> GetRsvpBuilder<'a, S>
where
    S: get_rsvp_state::State,
    S::Identity: get_rsvp_state::IsSet,
    S::Event: get_rsvp_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetRsvp<'a> {
        GetRsvp {
            event: self._fields.0.unwrap(),
            identity: self._fields.1.unwrap(),
        }
    }
}