// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.repo.listMissingBlobs
//
// 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_common::types::string::{AtUri, Cid};
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::com_atproto::repo::list_missing_blobs;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListMissingBlobs<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///Defaults to `500`. Min: 1. Max: 1000.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListMissingBlobsOutput<'a> {
    #[serde(borrow)]
    pub blobs: Vec<list_missing_blobs::RecordBlob<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RecordBlob<'a> {
    #[serde(borrow)]
    pub cid: Cid<'a>,
    #[serde(borrow)]
    pub record_uri: AtUri<'a>,
}

/// Response type for com.atproto.repo.listMissingBlobs
pub struct ListMissingBlobsResponse;
impl jacquard_common::xrpc::XrpcResp for ListMissingBlobsResponse {
    const NSID: &'static str = "com.atproto.repo.listMissingBlobs";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ListMissingBlobsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for ListMissingBlobs<'a> {
    const NSID: &'static str = "com.atproto.repo.listMissingBlobs";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListMissingBlobsResponse;
}

/// Endpoint type for com.atproto.repo.listMissingBlobs
pub struct ListMissingBlobsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListMissingBlobsRequest {
    const PATH: &'static str = "/xrpc/com.atproto.repo.listMissingBlobs";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = ListMissingBlobs<'de>;
    type Response = ListMissingBlobsResponse;
}

impl<'a> LexiconSchema for RecordBlob<'a> {
    fn nsid() -> &'static str {
        "com.atproto.repo.listMissingBlobs"
    }
    fn def_name() -> &'static str {
        "recordBlob"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_listMissingBlobs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_limit() -> Option<i64> {
    Some(500i64)
}

pub mod list_missing_blobs_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 {}
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {}
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {}
}

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

impl<'a> ListMissingBlobs<'a> {
    /// Create a new builder for this type
    pub fn new() -> ListMissingBlobsBuilder<'a, list_missing_blobs_state::Empty> {
        ListMissingBlobsBuilder::new()
    }
}

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

impl<'a, S: list_missing_blobs_state::State> ListMissingBlobsBuilder<'a, S> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `cursor` field to an Option value (optional)
    pub fn maybe_cursor(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: list_missing_blobs_state::State> ListMissingBlobsBuilder<'a, S> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> ListMissingBlobsBuilder<'a, S>
where
    S: list_missing_blobs_state::State,
{
    /// Build the final struct
    pub fn build(self) -> ListMissingBlobs<'a> {
        ListMissingBlobs {
            cursor: self._fields.0,
            limit: self._fields.1,
        }
    }
}

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

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

impl<'a> RecordBlob<'a> {
    /// Create a new builder for this type
    pub fn new() -> RecordBlobBuilder<'a, record_blob_state::Empty> {
        RecordBlobBuilder::new()
    }
}

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

impl<'a, S> RecordBlobBuilder<'a, S>
where
    S: record_blob_state::State,
    S::Cid: record_blob_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<'a>>,
    ) -> RecordBlobBuilder<'a, record_blob_state::SetCid<S>> {
        self._fields.0 = Option::Some(value.into());
        RecordBlobBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RecordBlobBuilder<'a, S>
where
    S: record_blob_state::State,
    S::RecordUri: record_blob_state::IsUnset,
{
    /// Set the `recordUri` field (required)
    pub fn record_uri(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> RecordBlobBuilder<'a, record_blob_state::SetRecordUri<S>> {
        self._fields.1 = Option::Some(value.into());
        RecordBlobBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RecordBlobBuilder<'a, S>
where
    S: record_blob_state::State,
    S::Cid: record_blob_state::IsSet,
    S::RecordUri: record_blob_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RecordBlob<'a> {
        RecordBlob {
            cid: self._fields.0.unwrap(),
            record_uri: 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>,
        >,
    ) -> RecordBlob<'a> {
        RecordBlob {
            cid: self._fields.0.unwrap(),
            record_uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_repo_listMissingBlobs() -> 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("com.atproto.repo.listMissingBlobs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("recordBlob"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("cid"), SmolStr::new_static("recordUri")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("recordUri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}