// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: chat.bsky.convo.sendMessage
//
// 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_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::chat_bsky::convo::MessageInput;
use crate::chat_bsky::convo::MessageView;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SendMessage<'a> {
    #[serde(borrow)]
    pub convo_id: CowStr<'a>,
    #[serde(borrow)]
    pub message: MessageInput<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SendMessageOutput<'a> {
    #[serde(flatten)]
    #[serde(borrow)]
    pub value: MessageView<'a>,
}

/// Response type for chat.bsky.convo.sendMessage
pub struct SendMessageResponse;
impl jacquard_common::xrpc::XrpcResp for SendMessageResponse {
    const NSID: &'static str = "chat.bsky.convo.sendMessage";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = SendMessageOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for SendMessage<'a> {
    const NSID: &'static str = "chat.bsky.convo.sendMessage";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = SendMessageResponse;
}

/// Endpoint type for chat.bsky.convo.sendMessage
pub struct SendMessageRequest;
impl jacquard_common::xrpc::XrpcEndpoint for SendMessageRequest {
    const PATH: &'static str = "/xrpc/chat.bsky.convo.sendMessage";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = SendMessage<'de>;
    type Response = SendMessageResponse;
}

pub mod send_message_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 Message;
        type ConvoId;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Message = Unset;
        type ConvoId = Unset;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMessage<S> {}
    impl<S: State> State for SetMessage<S> {
        type Message = Set<members::message>;
        type ConvoId = S::ConvoId;
    }
    ///State transition - sets the `convo_id` field to Set
    pub struct SetConvoId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetConvoId<S> {}
    impl<S: State> State for SetConvoId<S> {
        type Message = S::Message;
        type ConvoId = Set<members::convo_id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `message` field
        pub struct message(());
        ///Marker type for the `convo_id` field
        pub struct convo_id(());
    }
}

/// Builder for constructing an instance of this type
pub struct SendMessageBuilder<'a, S: send_message_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<MessageInput<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> SendMessage<'a> {
    /// Create a new builder for this type
    pub fn new() -> SendMessageBuilder<'a, send_message_state::Empty> {
        SendMessageBuilder::new()
    }
}

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

impl<'a, S> SendMessageBuilder<'a, S>
where
    S: send_message_state::State,
    S::ConvoId: send_message_state::IsUnset,
{
    /// Set the `convoId` field (required)
    pub fn convo_id(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> SendMessageBuilder<'a, send_message_state::SetConvoId<S>> {
        self._fields.0 = Option::Some(value.into());
        SendMessageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SendMessageBuilder<'a, S>
where
    S: send_message_state::State,
    S::Message: send_message_state::IsUnset,
{
    /// Set the `message` field (required)
    pub fn message(
        mut self,
        value: impl Into<MessageInput<'a>>,
    ) -> SendMessageBuilder<'a, send_message_state::SetMessage<S>> {
        self._fields.1 = Option::Some(value.into());
        SendMessageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SendMessageBuilder<'a, S>
where
    S: send_message_state::State,
    S::Message: send_message_state::IsSet,
    S::ConvoId: send_message_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SendMessage<'a> {
        SendMessage {
            convo_id: self._fields.0.unwrap(),
            message: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> SendMessage<'a> {
        SendMessage {
            convo_id: self._fields.0.unwrap(),
            message: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}