// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: chat.bsky.convo.getConvoAvailability
//
// 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::types::string::Did;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::chat_bsky::convo::ConvoView;

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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetConvoAvailabilityOutput<'a> {
    pub can_chat: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub convo: Option<ConvoView<'a>>,
}

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

impl<'a> jacquard_common::xrpc::XrpcRequest for GetConvoAvailability<'a> {
    const NSID: &'static str = "chat.bsky.convo.getConvoAvailability";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetConvoAvailabilityResponse;
}

/// Endpoint type for chat.bsky.convo.getConvoAvailability
pub struct GetConvoAvailabilityRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetConvoAvailabilityRequest {
    const PATH: &'static str = "/xrpc/chat.bsky.convo.getConvoAvailability";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetConvoAvailability<'de>;
    type Response = GetConvoAvailabilityResponse;
}

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

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

impl<'a> GetConvoAvailability<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetConvoAvailabilityBuilder<
        'a,
        get_convo_availability_state::Empty,
    > {
        GetConvoAvailabilityBuilder::new()
    }
}

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

impl<'a, S> GetConvoAvailabilityBuilder<'a, S>
where
    S: get_convo_availability_state::State,
    S::Members: get_convo_availability_state::IsUnset,
{
    /// Set the `members` field (required)
    pub fn members(
        mut self,
        value: impl Into<Vec<Did<'a>>>,
    ) -> GetConvoAvailabilityBuilder<'a, get_convo_availability_state::SetMembers<S>> {
        self._fields.0 = Option::Some(value.into());
        GetConvoAvailabilityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> GetConvoAvailabilityBuilder<'a, S>
where
    S: get_convo_availability_state::State,
    S::Members: get_convo_availability_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetConvoAvailability<'a> {
        GetConvoAvailability {
            members: self._fields.0.unwrap(),
        }
    }
}