// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.repo.listRecords
//
// 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::ident::AtIdentifier;
use jacquard_common::types::string::{AtUri, Nsid, Cid};
use jacquard_common::types::value::Data;
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_records;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListRecords<'a> {
    #[serde(borrow)]
    pub collection: Nsid<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    #[serde(borrow)]
    pub repo: AtIdentifier<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reverse: Option<bool>,
}


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


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

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

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

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

impl<'a> LexiconSchema for Record<'a> {
    fn nsid() -> &'static str {
        "com.atproto.repo.listRecords"
    }
    fn def_name() -> &'static str {
        "record"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_listRecords()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<'a> ListRecords<'a> {
    /// Create a new builder for this type
    pub fn new() -> ListRecordsBuilder<'a, list_records_state::Empty> {
        ListRecordsBuilder::new()
    }
}

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

impl<'a, S> ListRecordsBuilder<'a, S>
where
    S: list_records_state::State,
    S::Collection: list_records_state::IsUnset,
{
    /// Set the `collection` field (required)
    pub fn collection(
        mut self,
        value: impl Into<Nsid<'a>>,
    ) -> ListRecordsBuilder<'a, list_records_state::SetCollection<S>> {
        self._fields.0 = Option::Some(value.into());
        ListRecordsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: list_records_state::State> ListRecordsBuilder<'a, S> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = 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.1 = value;
        self
    }
}

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

impl<'a, S> ListRecordsBuilder<'a, S>
where
    S: list_records_state::State,
    S::Repo: list_records_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<AtIdentifier<'a>>,
    ) -> ListRecordsBuilder<'a, list_records_state::SetRepo<S>> {
        self._fields.3 = Option::Some(value.into());
        ListRecordsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: list_records_state::State> ListRecordsBuilder<'a, S> {
    /// Set the `reverse` field (optional)
    pub fn reverse(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `reverse` field to an Option value (optional)
    pub fn maybe_reverse(mut self, value: Option<bool>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> ListRecordsBuilder<'a, S>
where
    S: list_records_state::State,
    S::Repo: list_records_state::IsSet,
    S::Collection: list_records_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ListRecords<'a> {
        ListRecords {
            collection: self._fields.0.unwrap(),
            cursor: self._fields.1,
            limit: self._fields.2,
            repo: self._fields.3.unwrap(),
            reverse: self._fields.4,
        }
    }
}

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

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

impl<'a> Record<'a> {
    /// Create a new builder for this type
    pub fn new() -> RecordBuilder<'a, record_state::Empty> {
        RecordBuilder::new()
    }
}

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

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

impl<'a, S> RecordBuilder<'a, S>
where
    S: record_state::State,
    S::Uri: record_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> RecordBuilder<'a, record_state::SetUri<S>> {
        self._fields.1 = Option::Some(value.into());
        RecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RecordBuilder<'a, S>
where
    S: record_state::State,
    S::Value: record_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<Data<'a>>,
    ) -> RecordBuilder<'a, record_state::SetValue<S>> {
        self._fields.2 = Option::Some(value.into());
        RecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RecordBuilder<'a, S>
where
    S: record_state::State,
    S::Value: record_state::IsSet,
    S::Uri: record_state::IsSet,
    S::Cid: record_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Record<'a> {
        Record {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2.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, Data<'a>>,
    ) -> Record<'a> {
        Record {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_repo_listRecords() -> 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.listRecords"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(
                                vec![
                                    SmolStr::new_static("repo"),
                                    SmolStr::new_static("collection")
                                ],
                            ),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("collection"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("The NSID of the record type."),
                                        ),
                                        format: Some(LexStringFormat::Nsid),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("repo"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("The handle or DID of the repo."),
                                        ),
                                        format: Some(LexStringFormat::AtIdentifier),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("reverse"),
                                    LexXrpcParametersProperty::Boolean(LexBoolean {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("record"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("value")
                        ],
                    ),
                    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("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}