// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: chat.bsky.convo.sendMessageBatch
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::chat_bsky::convo::MessageInput;
use crate::chat_bsky::convo::MessageView;
use crate::chat_bsky::convo::send_message_batch;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct BatchItem<'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 SendMessageBatch<'a> {
    #[serde(borrow)]
    pub items: Vec<send_message_batch::BatchItem<'a>>,
}


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

impl<'a> LexiconSchema for BatchItem<'a> {
    fn nsid() -> &'static str {
        "chat.bsky.convo.sendMessageBatch"
    }
    fn def_name() -> &'static str {
        "batchItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_chat_bsky_convo_sendMessageBatch()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

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

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

impl<'a> BatchItem<'a> {
    /// Create a new builder for this type
    pub fn new() -> BatchItemBuilder<'a, batch_item_state::Empty> {
        BatchItemBuilder::new()
    }
}

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

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

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

impl<'a, S> BatchItemBuilder<'a, S>
where
    S: batch_item_state::State,
    S::ConvoId: batch_item_state::IsSet,
    S::Message: batch_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> BatchItem<'a> {
        BatchItem {
            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>,
        >,
    ) -> BatchItem<'a> {
        BatchItem {
            convo_id: self._fields.0.unwrap(),
            message: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_chat_bsky_convo_sendMessageBatch() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("chat.bsky.convo.sendMessageBatch"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("batchItem"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("convoId"),
                            SmolStr::new_static("message")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("convoId"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("message"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "chat.bsky.convo.defs#messageInput",
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(vec![SmolStr::new_static("items")]),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("items"),
                                        LexObjectProperty::Array(LexArray {
                                            items: LexArrayItem::Ref(LexRef {
                                                r#ref: CowStr::new_static("#batchItem"),
                                                ..Default::default()
                                            }),
                                            max_length: Some(100usize),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type
pub struct SendMessageBatchBuilder<'a, S: send_message_batch_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<send_message_batch::BatchItem<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> SendMessageBatch<'a> {
    /// Create a new builder for this type
    pub fn new() -> SendMessageBatchBuilder<'a, send_message_batch_state::Empty> {
        SendMessageBatchBuilder::new()
    }
}

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

impl<'a, S> SendMessageBatchBuilder<'a, S>
where
    S: send_message_batch_state::State,
    S::Items: send_message_batch_state::IsUnset,
{
    /// Set the `items` field (required)
    pub fn items(
        mut self,
        value: impl Into<Vec<send_message_batch::BatchItem<'a>>>,
    ) -> SendMessageBatchBuilder<'a, send_message_batch_state::SetItems<S>> {
        self._fields.0 = Option::Some(value.into());
        SendMessageBatchBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SendMessageBatchBuilder<'a, S>
where
    S: send_message_batch_state::State,
    S::Items: send_message_batch_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SendMessageBatch<'a> {
        SendMessageBatch {
            items: self._fields.0.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>,
        >,
    ) -> SendMessageBatch<'a> {
        SendMessageBatch {
            items: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}