// @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;

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

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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct FetchRecordsOutput<'a> {
    ///The results of the queries. Missing results indicate an error. For privacy, the error is not returned.
    #[serde(borrow)]
    pub results: Vec<fetch_records::FetchRecordsResult<'a>>,
}

/// Successful result, with the record value.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct FetchRecordsResult<'a> {
    ///The stored private record value.
    #[serde(borrow)]
    pub record: Data<'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>,
}

/// Response type for ooo.bsky.authfetch.fetchRecords
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<'de> = FetchRecordsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for ooo.bsky.authfetch.fetchRecords
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<'de> = FetchRecords<'de>;
    type Response = FetchRecordsResponse;
}

impl<'a> LexiconSchema for FetchRecordsResult<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUris<S> {}
    impl<S: State> State for SetUris<S> {
        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<'a, S: fetch_records_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<AtUri<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> FetchRecordsBuilder<'a, S>
where
    S: fetch_records_state::State,
    S::Uris: fetch_records_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> FetchRecords<'a> {
        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 Strategy;
        type Uri;
        type Record;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Strategy = Unset;
        type Uri = Unset;
        type Record = Unset;
    }
    ///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 Strategy = Set<members::strategy>;
        type Uri = S::Uri;
        type Record = S::Record;
    }
    ///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 Strategy = S::Strategy;
        type Uri = Set<members::uri>;
        type Record = S::Record;
    }
    ///State transition - sets the `record` field to Set
    pub struct SetRecord<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecord<S> {}
    impl<S: State> State for SetRecord<S> {
        type Strategy = S::Strategy;
        type Uri = S::Uri;
        type Record = Set<members::record>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `strategy` field
        pub struct strategy(());
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `record` field
        pub struct record(());
    }
}

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

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

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

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

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

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

impl<'a, S> FetchRecordsResultBuilder<'a, S>
where
    S: fetch_records_result_state::State,
    S::Strategy: fetch_records_result_state::IsSet,
    S::Uri: fetch_records_result_state::IsSet,
    S::Record: fetch_records_result_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> FetchRecordsResult<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> FetchRecordsResult<'a> {
        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()
    }
}