// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.repo.listSecrets
//
// 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, 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::{Did, AtUri, Datetime};
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::sh_tangled::repo::list_secrets;

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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListSecretsOutput<S: BosStr = DefaultStr> {
    pub secrets: Vec<list_secrets::Secret<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Secret<S: BosStr = DefaultStr> {
    pub created_at: Datetime,
    pub created_by: Did<S>,
    pub key: S,
    pub repo: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `sh.tangled.repo.listSecrets` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ListSecretsOutput<S>` for this endpoint.*/
pub struct ListSecretsResponse;
impl jacquard_common::xrpc::XrpcResp for ListSecretsResponse {
    const NSID: &'static str = "sh.tangled.repo.listSecrets";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ListSecretsOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ListSecrets<S> {
    const NSID: &'static str = "sh.tangled.repo.listSecrets";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListSecretsResponse;
}

/** Endpoint marker for the `sh.tangled.repo.listSecrets` query.

Path: `/xrpc/sh.tangled.repo.listSecrets`. The request payload type is `ListSecrets<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ListSecretsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListSecretsRequest {
    const PATH: &'static str = "/xrpc/sh.tangled.repo.listSecrets";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = ListSecrets<S>;
    type Response = ListSecretsResponse;
}

impl<S: BosStr> LexiconSchema for Secret<S> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.listSecrets"
    }
    fn def_name() -> &'static str {
        "secret"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_listSecrets()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.key;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("key"),
                    max: 50usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.key;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("key"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> ListSecrets<S> {
    /// Create a new builder for this type
    pub fn builder() -> ListSecretsBuilder<list_secrets_state::Empty, S> {
        ListSecretsBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ListSecretsBuilder<St, S>
where
    St: list_secrets_state::State,
    St::Repo: list_secrets_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ListSecretsBuilder<list_secrets_state::SetRepo<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ListSecretsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ListSecretsBuilder<St, S>
where
    St: list_secrets_state::State,
    St::Repo: list_secrets_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListSecrets<S> {
        ListSecrets {
            repo: self._fields.0.unwrap(),
        }
    }
}

pub mod secret_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 CreatedAt;
        type CreatedBy;
        type Key;
        type Repo;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type CreatedBy = Unset;
        type Key = Unset;
        type Repo = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type CreatedBy = St::CreatedBy;
        type Key = St::Key;
        type Repo = St::Repo;
    }
    ///State transition - sets the `created_by` field to Set
    pub struct SetCreatedBy<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedBy<St> {}
    impl<St: State> State for SetCreatedBy<St> {
        type CreatedAt = St::CreatedAt;
        type CreatedBy = Set<members::created_by>;
        type Key = St::Key;
        type Repo = St::Repo;
    }
    ///State transition - sets the `key` field to Set
    pub struct SetKey<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetKey<St> {}
    impl<St: State> State for SetKey<St> {
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Key = Set<members::key>;
        type Repo = St::Repo;
    }
    ///State transition - sets the `repo` field to Set
    pub struct SetRepo<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRepo<St> {}
    impl<St: State> State for SetRepo<St> {
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Key = St::Key;
        type Repo = Set<members::repo>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `created_by` field
        pub struct created_by(());
        ///Marker type for the `key` field
        pub struct key(());
        ///Marker type for the `repo` field
        pub struct repo(());
    }
}

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

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

impl<S: BosStr> Secret<S> {
    /// Create a new builder for this type
    pub fn builder() -> SecretBuilder<secret_state::Empty, S> {
        SecretBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SecretBuilder<St, S>
where
    St: secret_state::State,
    St::CreatedAt: secret_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SecretBuilder<secret_state::SetCreatedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SecretBuilder<St, S>
where
    St: secret_state::State,
    St::CreatedBy: secret_state::IsUnset,
{
    /// Set the `createdBy` field (required)
    pub fn created_by(
        mut self,
        value: impl Into<Did<S>>,
    ) -> SecretBuilder<secret_state::SetCreatedBy<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SecretBuilder<St, S>
where
    St: secret_state::State,
    St::Key: secret_state::IsUnset,
{
    /// Set the `key` field (required)
    pub fn key(
        mut self,
        value: impl Into<S>,
    ) -> SecretBuilder<secret_state::SetKey<St>, S> {
        self._fields.2 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SecretBuilder<St, S>
where
    St: secret_state::State,
    St::Repo: secret_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> SecretBuilder<secret_state::SetRepo<St>, S> {
        self._fields.3 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SecretBuilder<St, S>
where
    St: secret_state::State,
    St::CreatedAt: secret_state::IsSet,
    St::CreatedBy: secret_state::IsSet,
    St::Key: secret_state::IsSet,
    St::Repo: secret_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Secret<S> {
        Secret {
            created_at: self._fields.0.unwrap(),
            created_by: self._fields.1.unwrap(),
            key: self._fields.2.unwrap(),
            repo: self._fields.3.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>>) -> Secret<S> {
        Secret {
            created_at: self._fields.0.unwrap(),
            created_by: self._fields.1.unwrap(),
            key: self._fields.2.unwrap(),
            repo: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_tangled_repo_listSecrets() -> 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("sh.tangled.repo.listSecrets"),
        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")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("repo"),
                                    LexXrpcParametersProperty::String(LexString {
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("secret"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("repo"), SmolStr::new_static("key"),
                            SmolStr::new_static("createdAt"),
                            SmolStr::new_static("createdBy")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdBy"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("key"),
                            LexObjectProperty::String(LexString {
                                min_length: Some(1usize),
                                max_length: Some(50usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("repo"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}