// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.repo.blob
//
// 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::blob;

#[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<blob::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 Blob<'a> {
    #[serde(borrow)]
    pub path: CowStr<'a>,
    /// Defaults to `false`.
    #[serde(default = "_default_raw")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub raw: Option<bool>,
    #[serde(borrow)]
    pub r#ref: CowStr<'a>,
    #[serde(borrow)]
    pub repo: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct BlobOutput<'a> {
    ///File content (base64 encoded for binary files)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub content: Option<CowStr<'a>>,
    ///Content encoding
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub encoding: Option<CowStr<'a>>,
    ///Whether the file is binary
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_binary: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub last_commit: Option<blob::LastCommit<'a>>,
    ///MIME type of the file
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub mime_type: Option<CowStr<'a>>,
    ///The file path
    #[serde(borrow)]
    pub path: CowStr<'a>,
    ///The git reference used
    #[serde(borrow)]
    pub r#ref: CowStr<'a>,
    ///File size in bytes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<i64>,
    ///Submodule information if path is a submodule
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub submodule: Option<blob::Submodule<'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 BlobError<'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>>),
    /// File not found at the specified path
    #[serde(rename = "FileNotFound")]
    FileNotFound(Option<CowStr<'a>>),
    /// Invalid request parameters
    #[serde(rename = "InvalidRequest")]
    InvalidRequest(Option<CowStr<'a>>),
}

impl core::fmt::Display for BlobError<'_> {
    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::FileNotFound(msg) => {
                write!(f, "FileNotFound")?;
                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)]
#[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, Default)]
#[serde(rename_all = "camelCase")]
pub struct Submodule<'a> {
    ///Branch to track in the submodule
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub branch: Option<CowStr<'a>>,
    ///Submodule name
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///Submodule repository URL
    #[serde(borrow)]
    pub url: CowStr<'a>,
}

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

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

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

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

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

impl<'a> LexiconSchema for Submodule<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.blob"
    }
    fn def_name() -> &'static str {
        "submodule"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_blob()
    }
    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<blob::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<blob::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<blob::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_blob() -> 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.blob"),
        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"),
                                    SmolStr::new_static("path")
                                ],
                            ),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("path"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Path to the file within the repository"),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("raw"),
                                    LexXrpcParametersProperty::Boolean(LexBoolean {
                                        ..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("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("submodule"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("name"), SmolStr::new_static("url")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("branch"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Branch to track in the submodule"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Submodule name")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Submodule repository URL"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_raw() -> Option<bool> {
    Some(false)
}

pub mod blob_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;
        type Path;
    }
    /// 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;
        type Path = 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;
        type Path = S::Path;
    }
    ///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>;
        type Path = S::Path;
    }
    ///State transition - sets the `path` field to Set
    pub struct SetPath<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPath<S> {}
    impl<S: State> State for SetPath<S> {
        type Repo = S::Repo;
        type Ref = S::Ref;
        type Path = Set<members::path>;
    }
    /// 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(());
        ///Marker type for the `path` field
        pub struct path(());
    }
}

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

impl<'a> Blob<'a> {
    /// Create a new builder for this type
    pub fn new() -> BlobBuilder<'a, blob_state::Empty> {
        BlobBuilder::new()
    }
}

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

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

impl<'a, S: blob_state::State> BlobBuilder<'a, S> {
    /// Set the `raw` field (optional)
    pub fn raw(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `raw` field to an Option value (optional)
    pub fn maybe_raw(mut self, value: Option<bool>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<'a, S> BlobBuilder<'a, S>
where
    S: blob_state::State,
    S::Repo: blob_state::IsSet,
    S::Ref: blob_state::IsSet,
    S::Path: blob_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Blob<'a> {
        Blob {
            path: self._fields.0.unwrap(),
            raw: self._fields.1,
            r#ref: self._fields.2.unwrap(),
            repo: self._fields.3.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 When;
        type Email;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type When = Unset;
        type Email = Unset;
        type Name = Unset;
    }
    ///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 When = Set<members::when>;
        type Email = S::Email;
        type Name = S::Name;
    }
    ///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 When = S::When;
        type Email = Set<members::email>;
        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 When = S::When;
        type Email = S::Email;
        type Name = Set<members::name>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `when` field
        pub struct when(());
        ///Marker type for the `email` field
        pub struct email(());
        ///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::When: signature_state::IsSet,
    S::Email: 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),
        }
    }
}