// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: ooo.bsky.authfetch.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::string::{AtUri, Nsid};
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::ooo_bsky::authfetch::strategy::Strategy;
use crate::ooo_bsky::authfetch::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(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>>,
}

/// A record in the hidden repository.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Record<'a> {
    ///The strategy used to authenticate fetch requests for this record.
    #[serde(borrow)]
    pub strategy: Strategy<'a>,
    ///The AT URI of the record.
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    ///The stored private record value.
    #[serde(borrow)]
    pub value: Data<'a>,
}

/// Response type for ooo.bsky.authfetch.listRecords
pub struct ListRecordsResponse;
impl jacquard_common::xrpc::XrpcResp for ListRecordsResponse {
    const NSID: &'static str = "ooo.bsky.authfetch.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 = "ooo.bsky.authfetch.listRecords";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListRecordsResponse;
}

/// Endpoint type for ooo.bsky.authfetch.listRecords
pub struct ListRecordsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListRecordsRequest {
    const PATH: &'static str = "/xrpc/ooo.bsky.authfetch.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 {
        "ooo.bsky.authfetch.listRecords"
    }
    fn def_name() -> &'static str {
        "record"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_ooo_bsky_authfetch_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 Collection;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Collection = Unset;
    }
    ///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 Collection = Set<members::collection>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///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<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),
            _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: 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.3 = value.into();
        self
    }
    /// Set the `reverse` field to an Option value (optional)
    pub fn maybe_reverse(mut self, value: Option<bool>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> ListRecordsBuilder<'a, S>
where
    S: list_records_state::State,
    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,
            reverse: self._fields.3,
        }
    }
}

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

/// Builder for constructing an instance of this type
pub struct RecordBuilder<'a, S: record_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Strategy<'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::Strategy: record_state::IsUnset,
{
    /// Set the `strategy` field (required)
    pub fn strategy(
        mut self,
        value: impl Into<Strategy<'a>>,
    ) -> RecordBuilder<'a, record_state::SetStrategy<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::Uri: record_state::IsSet,
    S::Strategy: record_state::IsSet,
    S::Value: record_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Record<'a> {
        Record {
            strategy: 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 {
            strategy: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_ooo_bsky_authfetch_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("ooo.bsky.authfetch.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("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 collection."),
                                        ),
                                        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("reverse"),
                                    LexXrpcParametersProperty::Boolean(LexBoolean {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("record"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A record in the hidden repository."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("strategy"),
                            SmolStr::new_static("value")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("strategy"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("ooo.bsky.authfetch.strategy"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The AT URI of the record."),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}