// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.wisp.fs
//
// 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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
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::place_wisp::fs;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Directory<'a> {
    #[serde(borrow)]
    pub entries: Vec<fs::Entry<'a>>,
    #[serde(borrow)]
    pub r#type: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Entry<'a> {
    #[serde(borrow)]
    pub name: CowStr<'a>,
    #[serde(borrow)]
    pub node: EntryNode<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum EntryNode<'a> {
    #[serde(rename = "place.wisp.fs#file")]
    File(Box<fs::File<'a>>),
    #[serde(rename = "place.wisp.fs#directory")]
    Directory(Box<fs::Directory<'a>>),
    #[serde(rename = "place.wisp.fs#subfs")]
    Subfs(Box<fs::Subfs<'a>>),
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct File<'a> {
    ///True if blob content is base64-encoded (used to bypass PDS content sniffing)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub base64: Option<bool>,
    ///Content blob ref
    #[serde(borrow)]
    pub blob: BlobRef<'a>,
    ///Content encoding (e.g., gzip for compressed files)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub encoding: Option<CowStr<'a>>,
    ///Original MIME type before compression
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub mime_type: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub r#type: CowStr<'a>,
}

/// Virtual filesystem manifest for a Wisp site

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Fs<'a> {
    pub created_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file_count: Option<i64>,
    #[serde(borrow)]
    pub root: fs::Directory<'a>,
    #[serde(borrow)]
    pub site: CowStr<'a>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct FsGetRecordOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Fs<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Subfs<'a> {
    ///If true, the subfs record's root entries are merged (flattened) into the parent directory, replacing the subfs entry. If false (default), the subfs entries are placed in a subdirectory with the subfs entry's name. Flat merging is useful for splitting large directories across multiple records while maintaining a flat structure.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub flat: Option<bool>,
    ///AT-URI pointing to a place.wisp.subfs record containing this subtree.
    #[serde(borrow)]
    pub subject: AtUri<'a>,
    #[serde(borrow)]
    pub r#type: CowStr<'a>,
}

impl<'a> Fs<'a> {
    pub fn uri(uri: impl Into<CowStr<'a>>) -> Result<RecordUri<'a, FsRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

impl<'a> LexiconSchema for Directory<'a> {
    fn nsid() -> &'static str {
        "place.wisp.fs"
    }
    fn def_name() -> &'static str {
        "directory"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_wisp_fs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.entries;
            #[allow(unused_comparisons)]
            if value.len() > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("entries"),
                    max: 500usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Entry<'a> {
    fn nsid() -> &'static str {
        "place.wisp.fs"
    }
    fn def_name() -> &'static str {
        "entry"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_wisp_fs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 255usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 255usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for File<'a> {
    fn nsid() -> &'static str {
        "place.wisp.fs"
    }
    fn def_name() -> &'static str {
        "file"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_wisp_fs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.blob;
            {
                let size = value.blob().size;
                if size > 1000000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("blob"),
                        max: 1000000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.blob;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["*/*"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("blob"),
                        accepted: vec!["*/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct FsRecord;
impl XrpcResp for FsRecord {
    const NSID: &'static str = "place.wisp.fs";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = FsGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<FsGetRecordOutput<'_>> for Fs<'_> {
    fn from(output: FsGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Fs<'_> {
    const NSID: &'static str = "place.wisp.fs";
    type Record = FsRecord;
}

impl Collection for FsRecord {
    const NSID: &'static str = "place.wisp.fs";
    type Record = FsRecord;
}

impl<'a> LexiconSchema for Fs<'a> {
    fn nsid() -> &'static str {
        "place.wisp.fs"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_wisp_fs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.file_count {
            if *value > 1000i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("file_count"),
                    max: 1000i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.file_count {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("file_count"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Subfs<'a> {
    fn nsid() -> &'static str {
        "place.wisp.fs"
    }
    fn def_name() -> &'static str {
        "subfs"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_wisp_fs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

impl<'a> Directory<'a> {
    /// Create a new builder for this type
    pub fn new() -> DirectoryBuilder<'a, directory_state::Empty> {
        DirectoryBuilder::new()
    }
}

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

impl<'a, S> DirectoryBuilder<'a, S>
where
    S: directory_state::State,
    S::Entries: directory_state::IsUnset,
{
    /// Set the `entries` field (required)
    pub fn entries(
        mut self,
        value: impl Into<Vec<fs::Entry<'a>>>,
    ) -> DirectoryBuilder<'a, directory_state::SetEntries<S>> {
        self._fields.0 = Option::Some(value.into());
        DirectoryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> DirectoryBuilder<'a, S>
where
    S: directory_state::State,
    S::Type: directory_state::IsSet,
    S::Entries: directory_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Directory<'a> {
        Directory {
            entries: self._fields.0.unwrap(),
            r#type: self._fields.1.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>,
        >,
    ) -> Directory<'a> {
        Directory {
            entries: self._fields.0.unwrap(),
            r#type: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_wisp_fs() -> 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("place.wisp.fs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("directory"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("type"), SmolStr::new_static("entries")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("entries"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#entry"),
                                    ..Default::default()
                                }),
                                max_length: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("entry"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("name"), SmolStr::new_static("node")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(255usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("node"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("#file"),
                                    CowStr::new_static("#directory"),
                                    CowStr::new_static("#subfs")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("file"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("type"), SmolStr::new_static("blob")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("base64"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("blob"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("encoding"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Content encoding (e.g., gzip for compressed files)",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("mimeType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Original MIME type before compression"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("Virtual filesystem manifest for a Wisp site"),
                    ),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("site"), SmolStr::new_static("root"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("fileCount"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    maximum: Some(1000i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("root"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#directory"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("site"),
                                LexObjectProperty::String(LexString {
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("subfs"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("type"), SmolStr::new_static("subject")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("flat"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("subject"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "AT-URI pointing to a place.wisp.subfs record containing this subtree.",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod 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 Node;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Name = Unset;
        type Node = 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 Node = S::Node;
    }
    ///State transition - sets the `node` field to Set
    pub struct SetNode<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNode<S> {}
    impl<S: State> State for SetNode<S> {
        type Name = S::Name;
        type Node = Set<members::node>;
    }
    /// 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 `node` field
        pub struct node(());
    }
}

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

impl<'a> Entry<'a> {
    /// Create a new builder for this type
    pub fn new() -> EntryBuilder<'a, entry_state::Empty> {
        EntryBuilder::new()
    }
}

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

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

impl<'a, S> EntryBuilder<'a, S>
where
    S: entry_state::State,
    S::Node: entry_state::IsUnset,
{
    /// Set the `node` field (required)
    pub fn node(
        mut self,
        value: impl Into<EntryNode<'a>>,
    ) -> EntryBuilder<'a, entry_state::SetNode<S>> {
        self._fields.1 = Option::Some(value.into());
        EntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> EntryBuilder<'a, S>
where
    S: entry_state::State,
    S::Name: entry_state::IsSet,
    S::Node: entry_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Entry<'a> {
        Entry {
            name: self._fields.0.unwrap(),
            node: self._fields.1.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>,
        >,
    ) -> Entry<'a> {
        Entry {
            name: self._fields.0.unwrap(),
            node: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

impl<'a> File<'a> {
    /// Create a new builder for this type
    pub fn new() -> FileBuilder<'a, file_state::Empty> {
        FileBuilder::new()
    }
}

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

impl<'a, S: file_state::State> FileBuilder<'a, S> {
    /// Set the `base64` field (optional)
    pub fn base64(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `base64` field to an Option value (optional)
    pub fn maybe_base64(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> FileBuilder<'a, S>
where
    S: file_state::State,
    S::Blob: file_state::IsUnset,
{
    /// Set the `blob` field (required)
    pub fn blob(
        mut self,
        value: impl Into<BlobRef<'a>>,
    ) -> FileBuilder<'a, file_state::SetBlob<S>> {
        self._fields.1 = Option::Some(value.into());
        FileBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: file_state::State> FileBuilder<'a, S> {
    /// Set the `encoding` field (optional)
    pub fn encoding(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `encoding` field to an Option value (optional)
    pub fn maybe_encoding(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: file_state::State> FileBuilder<'a, S> {
    /// Set the `mimeType` field (optional)
    pub fn mime_type(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `mimeType` field to an Option value (optional)
    pub fn maybe_mime_type(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> FileBuilder<'a, S>
where
    S: file_state::State,
    S::Type: file_state::IsUnset,
{
    /// Set the `type` field (required)
    pub fn r#type(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> FileBuilder<'a, file_state::SetType<S>> {
        self._fields.4 = Option::Some(value.into());
        FileBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> FileBuilder<'a, S>
where
    S: file_state::State,
    S::Blob: file_state::IsSet,
    S::Type: file_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> File<'a> {
        File {
            base64: self._fields.0,
            blob: self._fields.1.unwrap(),
            encoding: self._fields.2,
            mime_type: self._fields.3,
            r#type: self._fields.4.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>,
        >,
    ) -> File<'a> {
        File {
            base64: self._fields.0,
            blob: self._fields.1.unwrap(),
            encoding: self._fields.2,
            mime_type: self._fields.3,
            r#type: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod fs_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 Root;
        type Site;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Root = Unset;
        type Site = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `root` field to Set
    pub struct SetRoot<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRoot<S> {}
    impl<S: State> State for SetRoot<S> {
        type Root = Set<members::root>;
        type Site = S::Site;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `site` field to Set
    pub struct SetSite<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSite<S> {}
    impl<S: State> State for SetSite<S> {
        type Root = S::Root;
        type Site = Set<members::site>;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Root = S::Root;
        type Site = S::Site;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `root` field
        pub struct root(());
        ///Marker type for the `site` field
        pub struct site(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

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

impl<'a> Fs<'a> {
    /// Create a new builder for this type
    pub fn new() -> FsBuilder<'a, fs_state::Empty> {
        FsBuilder::new()
    }
}

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

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

impl<'a, S: fs_state::State> FsBuilder<'a, S> {
    /// Set the `fileCount` field (optional)
    pub fn file_count(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `fileCount` field to an Option value (optional)
    pub fn maybe_file_count(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> FsBuilder<'a, S>
where
    S: fs_state::State,
    S::Root: fs_state::IsUnset,
{
    /// Set the `root` field (required)
    pub fn root(
        mut self,
        value: impl Into<fs::Directory<'a>>,
    ) -> FsBuilder<'a, fs_state::SetRoot<S>> {
        self._fields.2 = Option::Some(value.into());
        FsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> FsBuilder<'a, S>
where
    S: fs_state::State,
    S::Root: fs_state::IsSet,
    S::Site: fs_state::IsSet,
    S::CreatedAt: fs_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Fs<'a> {
        Fs {
            created_at: self._fields.0.unwrap(),
            file_count: self._fields.1,
            root: self._fields.2.unwrap(),
            site: 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>,
        >,
    ) -> Fs<'a> {
        Fs {
            created_at: self._fields.0.unwrap(),
            file_count: self._fields.1,
            root: self._fields.2.unwrap(),
            site: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

impl<'a> Subfs<'a> {
    /// Create a new builder for this type
    pub fn new() -> SubfsBuilder<'a, subfs_state::Empty> {
        SubfsBuilder::new()
    }
}

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

impl<'a, S: subfs_state::State> SubfsBuilder<'a, S> {
    /// Set the `flat` field (optional)
    pub fn flat(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `flat` field to an Option value (optional)
    pub fn maybe_flat(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> SubfsBuilder<'a, S>
where
    S: subfs_state::State,
    S::Subject: subfs_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> SubfsBuilder<'a, subfs_state::SetSubject<S>> {
        self._fields.1 = Option::Some(value.into());
        SubfsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> SubfsBuilder<'a, S>
where
    S: subfs_state::State,
    S::Subject: subfs_state::IsSet,
    S::Type: subfs_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Subfs<'a> {
        Subfs {
            flat: self._fields.0,
            subject: self._fields.1.unwrap(),
            r#type: 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>,
        >,
    ) -> Subfs<'a> {
        Subfs {
            flat: self._fields.0,
            subject: self._fields.1.unwrap(),
            r#type: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}