// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.repo.tree
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::Datetime;
use jacquard_derive::{IntoStatic, lexicon, 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::repo::tree;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LastCommit<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub author: Option<tree::Signature<'a>>,
    ///Commit hash
    #[serde(borrow)]
    pub hash: CowStr<'a>,
    ///Commit message
    #[serde(borrow)]
    pub message: CowStr<'a>,
    ///Commit timestamp
    pub when: Datetime,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Tree<'a> {
    ///Defaults to `""`.
    #[serde(default = "_default_path")]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub path: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub r#ref: CowStr<'a>,
    #[serde(borrow)]
    pub repo: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TreeOutput<'a> {
    ///Parent directory path
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub dotdot: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub files: Vec<tree::TreeEntry<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub last_commit: Option<tree::LastCommit<'a>>,
    ///The parent path in the tree
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub parent: Option<CowStr<'a>>,
    ///Readme for this file tree
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub readme: Option<tree::Readme<'a>>,
    ///The git reference used
    #[serde(borrow)]
    pub r#ref: CowStr<'a>,
}


#[open_union]
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    IntoStatic
)]

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum TreeError<'a> {
    /// Repository not found or access denied
    #[serde(rename = "RepoNotFound")]
    RepoNotFound(Option<CowStr<'a>>),
    /// Git reference not found
    #[serde(rename = "RefNotFound")]
    RefNotFound(Option<CowStr<'a>>),
    /// Path not found in repository tree
    #[serde(rename = "PathNotFound")]
    PathNotFound(Option<CowStr<'a>>),
    /// Invalid request parameters
    #[serde(rename = "InvalidRequest")]
    InvalidRequest(Option<CowStr<'a>>),
}

impl core::fmt::Display for TreeError<'_> {
    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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Readme<'a> {
    ///Contents of the readme file
    #[serde(borrow)]
    pub contents: CowStr<'a>,
    ///Name of the readme file
    #[serde(borrow)]
    pub filename: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Signature<'a> {
    ///Author email
    #[serde(borrow)]
    pub email: CowStr<'a>,
    ///Author name
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///Author timestamp
    pub when: Datetime,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TreeEntry<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub last_commit: Option<tree::LastCommit<'a>>,
    ///File mode
    #[serde(borrow)]
    pub mode: CowStr<'a>,
    ///Relative file or directory name
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///File size in bytes
    pub size: i64,
}

impl<'a> LexiconSchema for LastCommit<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.tree"
    }
    fn def_name() -> &'static str {
        "lastCommit"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_tree()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// Response type for sh.tangled.repo.tree
pub struct TreeResponse;
impl jacquard_common::xrpc::XrpcResp for TreeResponse {
    const NSID: &'static str = "sh.tangled.repo.tree";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = TreeOutput<'de>;
    type Err<'de> = TreeError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for Tree<'a> {
    const NSID: &'static str = "sh.tangled.repo.tree";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = TreeResponse;
}

/// Endpoint type for sh.tangled.repo.tree
pub struct TreeRequest;
impl jacquard_common::xrpc::XrpcEndpoint for TreeRequest {
    const PATH: &'static str = "/xrpc/sh.tangled.repo.tree";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = Tree<'de>;
    type Response = TreeResponse;
}

impl<'a> LexiconSchema for Readme<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.tree"
    }
    fn def_name() -> &'static str {
        "readme"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_tree()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Signature<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.tree"
    }
    fn def_name() -> &'static str {
        "signature"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_tree()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for TreeEntry<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.tree"
    }
    fn def_name() -> &'static str {
        "treeEntry"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_tree()
    }
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetHash<S> {}
    impl<S: State> State for SetHash<S> {
        type Hash = Set<members::hash>;
        type Message = S::Message;
        type When = S::When;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMessage<S> {}
    impl<S: State> State for SetMessage<S> {
        type Hash = S::Hash;
        type Message = Set<members::message>;
        type When = S::When;
    }
    ///State transition - sets the `when` field to Set
    pub struct SetWhen<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetWhen<S> {}
    impl<S: State> State for SetWhen<S> {
        type Hash = S::Hash;
        type Message = S::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<'a, S: last_commit_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<tree::Signature<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<Datetime>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

impl<'a, S> LastCommitBuilder<'a, S>
where
    S: last_commit_state::State,
    S::Hash: last_commit_state::IsSet,
    S::Message: last_commit_state::IsSet,
    S::When: last_commit_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> LastCommit<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> LastCommit<'a> {
        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_repo_tree() -> 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.tree"),
        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(
                                                "Repository identifier in format 'did:plc:.../repoName'",
                                            ),
                                        ),
                                        ..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() -> Option<CowStr<'static>> {
    Some(CowStr::from(""))
}

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

/// Builder for constructing an instance of this type
pub struct TreeBuilder<'a, S: tree_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Tree<'a> {
    /// Create a new builder for this type
    pub fn new() -> TreeBuilder<'a, tree_state::Empty> {
        TreeBuilder::new()
    }
}

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

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

impl<'a, S> TreeBuilder<'a, S>
where
    S: tree_state::State,
    S::Ref: tree_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> TreeBuilder<'a, tree_state::SetRef<S>> {
        self._fields.1 = Option::Some(value.into());
        TreeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> TreeBuilder<'a, S>
where
    S: tree_state::State,
    S::Repo: tree_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> TreeBuilder<'a, tree_state::SetRepo<S>> {
        self._fields.2 = Option::Some(value.into());
        TreeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> TreeBuilder<'a, S>
where
    S: tree_state::State,
    S::Repo: tree_state::IsSet,
    S::Ref: tree_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Tree<'a> {
        Tree {
            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 When;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Email = Unset;
        type When = Unset;
        type Name = Unset;
    }
    ///State transition - sets the `email` field to Set
    pub struct SetEmail<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEmail<S> {}
    impl<S: State> State for SetEmail<S> {
        type Email = Set<members::email>;
        type When = S::When;
        type Name = S::Name;
    }
    ///State transition - sets the `when` field to Set
    pub struct SetWhen<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetWhen<S> {}
    impl<S: State> State for SetWhen<S> {
        type Email = S::Email;
        type When = Set<members::when>;
        type Name = S::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Email = S::Email;
        type When = S::When;
        type Name = Set<members::name>;
    }
    /// 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 `when` field
        pub struct when(());
        ///Marker type for the `name` field
        pub struct name(());
    }
}

/// Builder for constructing an instance of this type
pub struct SignatureBuilder<'a, S: signature_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<Datetime>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> SignatureBuilder<'a, S>
where
    S: signature_state::State,
    S::Email: signature_state::IsSet,
    S::When: signature_state::IsSet,
    S::Name: signature_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Signature<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Signature<'a> {
        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 Name;
        type Size;
        type Mode;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Name = Unset;
        type Size = Unset;
        type Mode = Unset;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Name = Set<members::name>;
        type Size = S::Size;
        type Mode = S::Mode;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSize<S> {}
    impl<S: State> State for SetSize<S> {
        type Name = S::Name;
        type Size = Set<members::size>;
        type Mode = S::Mode;
    }
    ///State transition - sets the `mode` field to Set
    pub struct SetMode<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMode<S> {}
    impl<S: State> State for SetMode<S> {
        type Name = S::Name;
        type Size = S::Size;
        type Mode = Set<members::mode>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `size` field
        pub struct size(());
        ///Marker type for the `mode` field
        pub struct mode(());
    }
}

/// Builder for constructing an instance of this type
pub struct TreeEntryBuilder<'a, S: tree_entry_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<tree::LastCommit<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<i64>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: tree_entry_state::State> TreeEntryBuilder<'a, S> {
    /// Set the `last_commit` field (optional)
    pub fn last_commit(
        mut self,
        value: impl Into<Option<tree::LastCommit<'a>>>,
    ) -> 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<tree::LastCommit<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

impl<'a, S> TreeEntryBuilder<'a, S>
where
    S: tree_entry_state::State,
    S::Name: tree_entry_state::IsSet,
    S::Size: tree_entry_state::IsSet,
    S::Mode: tree_entry_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> TreeEntry<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> TreeEntry<'a> {
        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),
        }
    }
}