// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: events.smokesignal.event.configure
//
// 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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{AtUri, UriValue};
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 Configure<S: BosStr = DefaultStr> {
    ///When true, the RSVP button redirects to an external ticketing URL instead of creating a direct RSVP.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_direct_rsvp: Option<bool>,
    ///AT-URI of the event to configure.
    pub event: AtUri<S>,
    ///When true, RSVPs require a confirmed email address.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub require_confirmed_email: Option<bool>,
    ///URL to redirect users to for external ticketing (e.g., ti.to, eventbrite).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rsvp_redirect_url: Option<UriValue<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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ConfigureOutput<S: BosStr = DefaultStr> {
    #[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 ConfigureError {
    /// The specified event does not exist.
    #[serde(rename = "EventNotFound")]
    EventNotFound(Option<SmolStr>),
    /// The authenticated user does not own this event.
    #[serde(rename = "NotAuthorized")]
    NotAuthorized(Option<SmolStr>),
    /// The provided redirect URL is invalid or not allowed.
    #[serde(rename = "InvalidRedirectUrl")]
    InvalidRedirectUrl(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for ConfigureError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::EventNotFound(msg) => {
                write!(f, "EventNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::NotAuthorized(msg) => {
                write!(f, "NotAuthorized")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::InvalidRedirectUrl(msg) => {
                write!(f, "InvalidRedirectUrl")?;
                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(())
            }
        }
    }
}

/** Response marker for the `events.smokesignal.event.configure` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ConfigureOutput<S>` for this endpoint.*/
pub struct ConfigureResponse;
impl jacquard_common::xrpc::XrpcResp for ConfigureResponse {
    const NSID: &'static str = "events.smokesignal.event.configure";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ConfigureOutput<S>;
    type Err = ConfigureError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Configure<S> {
    const NSID: &'static str = "events.smokesignal.event.configure";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = ConfigureResponse;
}

/** Endpoint marker for the `events.smokesignal.event.configure` procedure.

Path: `/xrpc/events.smokesignal.event.configure`. The request payload type is `Configure<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ConfigureRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ConfigureRequest {
    const PATH: &'static str = "/xrpc/events.smokesignal.event.configure";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = Configure<S>;
    type Response = ConfigureResponse;
}

pub mod configure_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 Event;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Event = Unset;
    }
    ///State transition - sets the `event` field to Set
    pub struct SetEvent<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEvent<St> {}
    impl<St: State> State for SetEvent<St> {
        type Event = Set<members::event>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `event` field
        pub struct event(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ConfigureBuilder<St: configure_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<bool>, Option<AtUri<S>>, Option<bool>, Option<UriValue<S>>),
    _type: PhantomData<fn() -> S>,
}

impl Configure<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> ConfigureBuilder<configure_state::Empty, DefaultStr> {
        ConfigureBuilder::new()
    }
}

impl<S: BosStr> Configure<S> {
    /// Create a new builder for this type
    pub fn builder() -> ConfigureBuilder<configure_state::Empty, S> {
        ConfigureBuilder::builder()
    }
}

impl ConfigureBuilder<configure_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        ConfigureBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> ConfigureBuilder<configure_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        ConfigureBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St: configure_state::State, S: BosStr> ConfigureBuilder<St, S> {
    /// Set the `disableDirectRsvp` field (optional)
    pub fn disable_direct_rsvp(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `disableDirectRsvp` field to an Option value (optional)
    pub fn maybe_disable_direct_rsvp(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> ConfigureBuilder<St, S>
where
    St: configure_state::State,
    St::Event: configure_state::IsUnset,
{
    /// Set the `event` field (required)
    pub fn event(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ConfigureBuilder<configure_state::SetEvent<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ConfigureBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: configure_state::State, S: BosStr> ConfigureBuilder<St, S> {
    /// Set the `requireConfirmedEmail` field (optional)
    pub fn require_confirmed_email(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `requireConfirmedEmail` field to an Option value (optional)
    pub fn maybe_require_confirmed_email(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: configure_state::State, S: BosStr> ConfigureBuilder<St, S> {
    /// Set the `rsvpRedirectUrl` field (optional)
    pub fn rsvp_redirect_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `rsvpRedirectUrl` field to an Option value (optional)
    pub fn maybe_rsvp_redirect_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> ConfigureBuilder<St, S>
where
    St: configure_state::State,
    St::Event: configure_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Configure<S> {
        Configure {
            disable_direct_rsvp: self._fields.0,
            event: self._fields.1.unwrap(),
            require_confirmed_email: self._fields.2,
            rsvp_redirect_url: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Configure<S> {
        Configure {
            disable_direct_rsvp: self._fields.0,
            event: self._fields.1.unwrap(),
            require_confirmed_email: self._fields.2,
            rsvp_redirect_url: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}