// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.git.temp.getTree
//
// 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, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
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::git::temp::get_tree;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LastCommit<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub author: Option<get_tree::Signature<S>>,
    ///Commit hash
    pub hash: S,
    ///Commit message
    pub message: S,
    ///Commit timestamp
    pub when: Datetime,
    #[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 GetTree<S: BosStr = DefaultStr> {
    /// Defaults to `""`.
    #[serde(default = "_default_path")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<S>,
    pub r#ref: S,
    pub repo: Did<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetTreeOutput<S: BosStr = DefaultStr> {
    ///Parent directory path
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dotdot: Option<S>,
    pub files: Vec<get_tree::TreeEntry<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_commit: Option<get_tree::LastCommit<S>>,
    ///The parent path in the tree
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent: Option<S>,
    ///Readme for this file tree
    #[serde(skip_serializing_if = "Option::is_none")]
    pub readme: Option<get_tree::Readme<S>>,
    ///The git reference used
    pub r#ref: 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,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum GetTreeError {
    /// Repository not found or access denied
    #[serde(rename = "RepoNotFound")]
    RepoNotFound(Option<SmolStr>),
    /// Git reference not found
    #[serde(rename = "RefNotFound")]
    RefNotFound(Option<SmolStr>),
    /// Path not found in repository tree
    #[serde(rename = "PathNotFound")]
    PathNotFound(Option<SmolStr>),
    /// Invalid request parameters
    #[serde(rename = "InvalidRequest")]
    InvalidRequest(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for GetTreeError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::RepoNotFound(msg) => {
                write!(f, "RepoNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::RefNotFound(msg) => {
                write!(f, "RefNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::PathNotFound(msg) => {
                write!(f, "PathNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::InvalidRequest(msg) => {
                write!(f, "InvalidRequest")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Readme<S: BosStr = DefaultStr> {
    ///Contents of the readme file
    pub contents: S,
    ///Name of the readme file
    pub filename: 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 Signature<S: BosStr = DefaultStr> {
    ///Author email
    pub email: S,
    ///Author name
    pub name: S,
    ///Author timestamp
    pub when: Datetime,
    #[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 TreeEntry<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_commit: Option<get_tree::LastCommit<S>>,
    ///File mode
    pub mode: S,
    ///Relative file or directory name
    pub name: S,
    ///File size in bytes
    pub size: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for LastCommit<S> {
    fn nsid() -> &'static str {
        "sh.tangled.git.temp.getTree"
    }
    fn def_name() -> &'static str {
        "lastCommit"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_temp_getTree()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `sh.tangled.git.temp.getTree` query.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetTree<S> {
    const NSID: &'static str = "sh.tangled.git.temp.getTree";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetTreeResponse;
}

/** Endpoint marker for the `sh.tangled.git.temp.getTree` query.

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

impl<S: BosStr> LexiconSchema for Readme<S> {
    fn nsid() -> &'static str {
        "sh.tangled.git.temp.getTree"
    }
    fn def_name() -> &'static str {
        "readme"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_temp_getTree()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Signature<S> {
    fn nsid() -> &'static str {
        "sh.tangled.git.temp.getTree"
    }
    fn def_name() -> &'static str {
        "signature"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_temp_getTree()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for TreeEntry<S> {
    fn nsid() -> &'static str {
        "sh.tangled.git.temp.getTree"
    }
    fn def_name() -> &'static str {
        "treeEntry"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_temp_getTree()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod last_commit_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 Hash;
        type Message;
        type When;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Hash = Unset;
        type Message = Unset;
        type When = Unset;
    }
    ///State transition - sets the `hash` field to Set
    pub struct SetHash<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHash<St> {}
    impl<St: State> State for SetHash<St> {
        type Hash = Set<members::hash>;
        type Message = St::Message;
        type When = St::When;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMessage<St> {}
    impl<St: State> State for SetMessage<St> {
        type Hash = St::Hash;
        type Message = Set<members::message>;
        type When = St::When;
    }
    ///State transition - sets the `when` field to Set
    pub struct SetWhen<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetWhen<St> {}
    impl<St: State> State for SetWhen<St> {
        type Hash = St::Hash;
        type Message = St::Message;
        type When = Set<members::when>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `hash` field
        pub struct hash(());
        ///Marker type for the `message` field
        pub struct message(());
        ///Marker type for the `when` field
        pub struct when(());
    }
}

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

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

impl<S: BosStr> LastCommit<S> {
    /// Create a new builder for this type
    pub fn builder() -> LastCommitBuilder<last_commit_state::Empty, S> {
        LastCommitBuilder::builder()
    }
}

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

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

impl<St: last_commit_state::State, S: BosStr> LastCommitBuilder<St, S> {
    /// Set the `author` field (optional)
    pub fn author(mut self, value: impl Into<Option<get_tree::Signature<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `author` field to an Option value (optional)
    pub fn maybe_author(mut self, value: Option<get_tree::Signature<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> LastCommitBuilder<St, S>
where
    St: last_commit_state::State,
    St::Hash: last_commit_state::IsUnset,
{
    /// Set the `hash` field (required)
    pub fn hash(
        mut self,
        value: impl Into<S>,
    ) -> LastCommitBuilder<last_commit_state::SetHash<St>, S> {
        self._fields.1 = Option::Some(value.into());
        LastCommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LastCommitBuilder<St, S>
where
    St: last_commit_state::State,
    St::Message: last_commit_state::IsUnset,
{
    /// Set the `message` field (required)
    pub fn message(
        mut self,
        value: impl Into<S>,
    ) -> LastCommitBuilder<last_commit_state::SetMessage<St>, S> {
        self._fields.2 = Option::Some(value.into());
        LastCommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LastCommitBuilder<St, S>
where
    St: last_commit_state::State,
    St::When: last_commit_state::IsUnset,
{
    /// Set the `when` field (required)
    pub fn when(
        mut self,
        value: impl Into<Datetime>,
    ) -> LastCommitBuilder<last_commit_state::SetWhen<St>, S> {
        self._fields.3 = Option::Some(value.into());
        LastCommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LastCommitBuilder<St, S>
where
    St: last_commit_state::State,
    St::Hash: last_commit_state::IsSet,
    St::Message: last_commit_state::IsSet,
    St::When: last_commit_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> LastCommit<S> {
        LastCommit {
            author: self._fields.0,
            hash: self._fields.1.unwrap(),
            message: self._fields.2.unwrap(),
            when: 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>>,
    ) -> LastCommit<S> {
        LastCommit {
            author: self._fields.0,
            hash: self._fields.1.unwrap(),
            message: self._fields.2.unwrap(),
            when: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_tangled_git_temp_getTree() -> 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.git.temp.getTree"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("lastCommit"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("hash"), SmolStr::new_static("message"),
                            SmolStr::new_static("when")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("author"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#signature"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("hash"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Commit hash")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("message"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Commit message")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("when"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Commit timestamp")),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(
                                vec![
                                    SmolStr::new_static("repo"), SmolStr::new_static("ref")
                                ],
                            ),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("path"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Path within the repository tree"),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("ref"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "Git reference (branch, tag, or commit SHA)",
                                            ),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("repo"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("DID of the repository"),
                                        ),
                                        format: Some(LexStringFormat::Did),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("readme"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("filename"),
                            SmolStr::new_static("contents")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("contents"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Contents of the readme file"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("filename"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Name of the readme file"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("signature"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("name"), SmolStr::new_static("email"),
                            SmolStr::new_static("when")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("email"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Author email")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Author name")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("when"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Author timestamp")),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("treeEntry"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("name"), SmolStr::new_static("mode"),
                            SmolStr::new_static("size")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("last_commit"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#lastCommit"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("mode"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("File mode")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Relative file or directory name"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("size"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_path<S: jacquard_common::FromStaticStr>() -> Option<S> {
    Some(S::from_static(""))
}

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

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

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

impl<S: BosStr> GetTree<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetTreeBuilder<get_tree_state::Empty, S> {
        GetTreeBuilder::builder()
    }
}

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

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

impl<St: get_tree_state::State, S: BosStr> GetTreeBuilder<St, S> {
    /// Set the `path` field (optional)
    pub fn path(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `path` field to an Option value (optional)
    pub fn maybe_path(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> GetTreeBuilder<St, S>
where
    St: get_tree_state::State,
    St::Ref: get_tree_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<S>,
    ) -> GetTreeBuilder<get_tree_state::SetRef<St>, S> {
        self._fields.1 = Option::Some(value.into());
        GetTreeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> GetTreeBuilder<St, S>
where
    St: get_tree_state::State,
    St::Ref: get_tree_state::IsSet,
    St::Repo: get_tree_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetTree<S> {
        GetTree {
            path: self._fields.0,
            r#ref: self._fields.1.unwrap(),
            repo: self._fields.2.unwrap(),
        }
    }
}

pub mod signature_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 Email;
        type Name;
        type When;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Email = Unset;
        type Name = Unset;
        type When = Unset;
    }
    ///State transition - sets the `email` field to Set
    pub struct SetEmail<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEmail<St> {}
    impl<St: State> State for SetEmail<St> {
        type Email = Set<members::email>;
        type Name = St::Name;
        type When = St::When;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Email = St::Email;
        type Name = Set<members::name>;
        type When = St::When;
    }
    ///State transition - sets the `when` field to Set
    pub struct SetWhen<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetWhen<St> {}
    impl<St: State> State for SetWhen<St> {
        type Email = St::Email;
        type Name = St::Name;
        type When = Set<members::when>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `email` field
        pub struct email(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `when` field
        pub struct when(());
    }
}

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

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

impl<S: BosStr> Signature<S> {
    /// Create a new builder for this type
    pub fn builder() -> SignatureBuilder<signature_state::Empty, S> {
        SignatureBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SignatureBuilder<St, S>
where
    St: signature_state::State,
    St::Email: signature_state::IsUnset,
{
    /// Set the `email` field (required)
    pub fn email(
        mut self,
        value: impl Into<S>,
    ) -> SignatureBuilder<signature_state::SetEmail<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SignatureBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SignatureBuilder<St, S>
where
    St: signature_state::State,
    St::Name: signature_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<S>,
    ) -> SignatureBuilder<signature_state::SetName<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SignatureBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SignatureBuilder<St, S>
where
    St: signature_state::State,
    St::When: signature_state::IsUnset,
{
    /// Set the `when` field (required)
    pub fn when(
        mut self,
        value: impl Into<Datetime>,
    ) -> SignatureBuilder<signature_state::SetWhen<St>, S> {
        self._fields.2 = Option::Some(value.into());
        SignatureBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SignatureBuilder<St, S>
where
    St: signature_state::State,
    St::Email: signature_state::IsSet,
    St::Name: signature_state::IsSet,
    St::When: signature_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Signature<S> {
        Signature {
            email: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            when: 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>>,
    ) -> Signature<S> {
        Signature {
            email: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            when: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod tree_entry_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 Mode;
        type Name;
        type Size;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Mode = Unset;
        type Name = Unset;
        type Size = Unset;
    }
    ///State transition - sets the `mode` field to Set
    pub struct SetMode<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMode<St> {}
    impl<St: State> State for SetMode<St> {
        type Mode = Set<members::mode>;
        type Name = St::Name;
        type Size = St::Size;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Mode = St::Mode;
        type Name = Set<members::name>;
        type Size = St::Size;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSize<St> {}
    impl<St: State> State for SetSize<St> {
        type Mode = St::Mode;
        type Name = St::Name;
        type Size = Set<members::size>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `mode` field
        pub struct mode(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `size` field
        pub struct size(());
    }
}

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

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

impl<S: BosStr> TreeEntry<S> {
    /// Create a new builder for this type
    pub fn builder() -> TreeEntryBuilder<tree_entry_state::Empty, S> {
        TreeEntryBuilder::builder()
    }
}

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

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

impl<St: tree_entry_state::State, S: BosStr> TreeEntryBuilder<St, S> {
    /// Set the `last_commit` field (optional)
    pub fn last_commit(
        mut self,
        value: impl Into<Option<get_tree::LastCommit<S>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `last_commit` field to an Option value (optional)
    pub fn maybe_last_commit(mut self, value: Option<get_tree::LastCommit<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> TreeEntryBuilder<St, S>
where
    St: tree_entry_state::State,
    St::Mode: tree_entry_state::IsUnset,
{
    /// Set the `mode` field (required)
    pub fn mode(
        mut self,
        value: impl Into<S>,
    ) -> TreeEntryBuilder<tree_entry_state::SetMode<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TreeEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TreeEntryBuilder<St, S>
where
    St: tree_entry_state::State,
    St::Name: tree_entry_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<S>,
    ) -> TreeEntryBuilder<tree_entry_state::SetName<St>, S> {
        self._fields.2 = Option::Some(value.into());
        TreeEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TreeEntryBuilder<St, S>
where
    St: tree_entry_state::State,
    St::Size: tree_entry_state::IsUnset,
{
    /// Set the `size` field (required)
    pub fn size(
        mut self,
        value: impl Into<i64>,
    ) -> TreeEntryBuilder<tree_entry_state::SetSize<St>, S> {
        self._fields.3 = Option::Some(value.into());
        TreeEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TreeEntryBuilder<St, S>
where
    St: tree_entry_state::State,
    St::Mode: tree_entry_state::IsSet,
    St::Name: tree_entry_state::IsSet,
    St::Size: tree_entry_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TreeEntry<S> {
        TreeEntry {
            last_commit: self._fields.0,
            mode: self._fields.1.unwrap(),
            name: self._fields.2.unwrap(),
            size: 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>>,
    ) -> TreeEntry<S> {
        TreeEntry {
            last_commit: self._fields.0,
            mode: self._fields.1.unwrap(),
            name: self._fields.2.unwrap(),
            size: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}