// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: ooo.bsky.authfetch.fetchRecords
//
// 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::{BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::fetch_records;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct FetchRecords<S: BosStr = DefaultStr> {
    pub uris: Vec<AtUri<S>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct FetchRecordsOutput<S: BosStr = DefaultStr> {
    ///The results of the queries. Missing results indicate an error. For privacy, the error is not returned.
    pub results: Vec<fetch_records::FetchRecordsResult<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Successful result, with the record value.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct FetchRecordsResult<S: BosStr = DefaultStr> {
    ///The stored private record value.
    pub record: Data<S>,
    ///The strategy used to authenticate fetch requests for this record.
    pub strategy: Strategy<S>,
    ///The AT URI of the record.
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `ooo.bsky.authfetch.fetchRecords` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `FetchRecordsOutput<S>` for this endpoint.*/
pub struct FetchRecordsResponse;
impl jacquard_common::xrpc::XrpcResp for FetchRecordsResponse {
    const NSID: &'static str = "ooo.bsky.authfetch.fetchRecords";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = FetchRecordsOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for FetchRecords<S> {
    const NSID: &'static str = "ooo.bsky.authfetch.fetchRecords";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = FetchRecordsResponse;
}

/** Endpoint marker for the `ooo.bsky.authfetch.fetchRecords` query.

Path: `/xrpc/ooo.bsky.authfetch.fetchRecords`. The request payload type is `FetchRecords<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct FetchRecordsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for FetchRecordsRequest {
    const PATH: &'static str = "/xrpc/ooo.bsky.authfetch.fetchRecords";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = FetchRecords<S>;
    type Response = FetchRecordsResponse;
}

impl<S: BosStr> LexiconSchema for FetchRecordsResult<S> {
    fn nsid() -> &'static str {
        "ooo.bsky.authfetch.fetchRecords"
    }
    fn def_name() -> &'static str {
        "result"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_ooo_bsky_authfetch_fetchRecords()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

/// Builder for constructing an instance of this type.
pub struct FetchRecordsBuilder<St: fetch_records_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Vec<AtUri<S>>>,),
    _type: PhantomData<fn() -> S>,
}

impl FetchRecords<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> FetchRecordsBuilder<fetch_records_state::Empty, DefaultStr> {
        FetchRecordsBuilder::new()
    }
}

impl<S: BosStr> FetchRecords<S> {
    /// Create a new builder for this type
    pub fn builder() -> FetchRecordsBuilder<fetch_records_state::Empty, S> {
        FetchRecordsBuilder::builder()
    }
}

impl FetchRecordsBuilder<fetch_records_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        FetchRecordsBuilder {
            _state: PhantomData,
            _fields: (None,),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> FetchRecordsBuilder<fetch_records_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        FetchRecordsBuilder {
            _state: PhantomData,
            _fields: (None,),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FetchRecordsBuilder<St, S>
where
    St: fetch_records_state::State,
    St::Uris: fetch_records_state::IsUnset,
{
    /// Set the `uris` field (required)
    pub fn uris(
        mut self,
        value: impl Into<Vec<AtUri<S>>>,
    ) -> FetchRecordsBuilder<fetch_records_state::SetUris<St>, S> {
        self._fields.0 = Option::Some(value.into());
        FetchRecordsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FetchRecordsBuilder<St, S>
where
    St: fetch_records_state::State,
    St::Uris: fetch_records_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> FetchRecords<S> {
        FetchRecords {
            uris: self._fields.0.unwrap(),
        }
    }
}

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

/// Builder for constructing an instance of this type.
pub struct FetchRecordsResultBuilder<
    St: fetch_records_result_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Data<S>>, Option<Strategy<S>>, Option<AtUri<S>>),
    _type: PhantomData<fn() -> S>,
}

impl FetchRecordsResult<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> FetchRecordsResultBuilder<
        fetch_records_result_state::Empty,
        DefaultStr,
    > {
        FetchRecordsResultBuilder::new()
    }
}

impl<S: BosStr> FetchRecordsResult<S> {
    /// Create a new builder for this type
    pub fn builder() -> FetchRecordsResultBuilder<fetch_records_result_state::Empty, S> {
        FetchRecordsResultBuilder::builder()
    }
}

impl FetchRecordsResultBuilder<fetch_records_result_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        FetchRecordsResultBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> FetchRecordsResultBuilder<fetch_records_result_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        FetchRecordsResultBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FetchRecordsResultBuilder<St, S>
where
    St: fetch_records_result_state::State,
    St::Record: fetch_records_result_state::IsUnset,
{
    /// Set the `record` field (required)
    pub fn record(
        mut self,
        value: impl Into<Data<S>>,
    ) -> FetchRecordsResultBuilder<fetch_records_result_state::SetRecord<St>, S> {
        self._fields.0 = Option::Some(value.into());
        FetchRecordsResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FetchRecordsResultBuilder<St, S>
where
    St: fetch_records_result_state::State,
    St::Strategy: fetch_records_result_state::IsUnset,
{
    /// Set the `strategy` field (required)
    pub fn strategy(
        mut self,
        value: impl Into<Strategy<S>>,
    ) -> FetchRecordsResultBuilder<fetch_records_result_state::SetStrategy<St>, S> {
        self._fields.1 = Option::Some(value.into());
        FetchRecordsResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FetchRecordsResultBuilder<St, S>
where
    St: fetch_records_result_state::State,
    St::Uri: fetch_records_result_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> FetchRecordsResultBuilder<fetch_records_result_state::SetUri<St>, S> {
        self._fields.2 = Option::Some(value.into());
        FetchRecordsResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FetchRecordsResultBuilder<St, S>
where
    St: fetch_records_result_state::State,
    St::Record: fetch_records_result_state::IsSet,
    St::Strategy: fetch_records_result_state::IsSet,
    St::Uri: fetch_records_result_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> FetchRecordsResult<S> {
        FetchRecordsResult {
            record: self._fields.0.unwrap(),
            strategy: self._fields.1.unwrap(),
            uri: 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<SmolStr, Data<S>>,
    ) -> FetchRecordsResult<S> {
        FetchRecordsResult {
            record: self._fields.0.unwrap(),
            strategy: self._fields.1.unwrap(),
            uri: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_ooo_bsky_authfetch_fetchRecords() -> 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.fetchRecords"),
        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("uris")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("uris"),
                                    LexXrpcParametersProperty::Array(LexPrimitiveArray {
                                        items: LexPrimitiveArrayItem::String(LexString {
                                            format: Some(LexStringFormat::AtUri),
                                            ..Default::default()
                                        }),
                                        min_length: Some(1usize),
                                        max_length: Some(50usize),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("result"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Successful result, with the record value."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("strategy"),
                            SmolStr::new_static("record")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("record"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        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
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}