// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: science.alt.dataset.entry
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

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

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::bytes::Bytes;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
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::types::value::Data;
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::science_alt::dataset::storage_blobs::StorageBlobs;
use crate::science_alt::dataset::storage_http::StorageHttp;
use crate::science_alt::dataset::storage_s3::StorageS3;
use crate::science_alt::dataset::entry;
/// Information about dataset size

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DatasetSize<S: BosStr = DefaultStr> {
    ///Total size in bytes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bytes: Option<i64>,
    ///Total number of samples in the dataset
    #[serde(skip_serializing_if = "Option::is_none")]
    pub samples: Option<i64>,
    ///Number of WebDataset shards
    #[serde(skip_serializing_if = "Option::is_none")]
    pub shards: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Index entry for a WebDataset-backed dataset with references to storage location and sample schema

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "science.alt.dataset.entry",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Entry<S: BosStr = DefaultStr> {
    ///Dataset-level content metadata (e.g., instrument settings, acquisition parameters). Structure is validated against the schema referenced by metadataSchemaRef when present. Stored as an open JSON object.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content_metadata: Option<Data<S>>,
    ///Timestamp when this dataset entry was created
    pub created_at: Datetime,
    ///Human-readable description of the dataset
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///License identifier or URL. SPDX identifiers recommended (e.g., MIT, Apache-2.0, CC-BY-4.0) or full SPDX URLs (e.g., http://spdx.org/licenses/MIT). Aligns with Schema.org license property.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub license: Option<S>,
    ///Msgpack-encoded metadata dict for arbitrary extended key-value pairs. Use this for additional metadata beyond the core top-level fields (license, tags, size). Top-level fields are preferred for discoverable/searchable metadata.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default, with = "jacquard_common::opt_serde_bytes_helper")]
    pub metadata: Option<Bytes>,
    ///Optional AT-URI reference to a schema record defining the structure of this dataset's content metadata. When present, contentMetadata is validated against this schema at write time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata_schema_ref: Option<AtUri<S>>,
    ///Human-readable dataset name
    pub name: S,
    ///AT-URI reference to the schema record for this dataset's samples
    pub schema_ref: AtUri<S>,
    ///Dataset size information (optional)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<entry::DatasetSize<S>>,
    ///Storage location for dataset files (WebDataset tar archives)
    pub storage: EntryStorage<S>,
    ///Searchable tags for dataset discovery. Aligns with Schema.org keywords property.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum EntryStorage<S: BosStr = DefaultStr> {
    #[serde(rename = "science.alt.dataset.storageHttp")]
    StorageHttp(Box<StorageHttp<S>>),
    #[serde(rename = "science.alt.dataset.storageS3")]
    StorageS3(Box<StorageS3<S>>),
    #[serde(rename = "science.alt.dataset.storageBlobs")]
    StorageBlobs(Box<StorageBlobs<S>>),
}

/// 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 EntryGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Entry<S>,
}

/// Content hash for shard integrity verification. Algorithm is flexible to allow SHA-256, BLAKE3, or other hash functions.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ShardChecksum<S: BosStr = DefaultStr> {
    ///Hash algorithm identifier (e.g., 'sha256', 'blake3')
    pub algorithm: S,
    ///Hex-encoded hash digest
    pub digest: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> Entry<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, EntryRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

impl<S: BosStr> LexiconSchema for DatasetSize<S> {
    fn nsid() -> &'static str {
        "science.alt.dataset.entry"
    }
    fn def_name() -> &'static str {
        "datasetSize"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_science_alt_dataset_entry()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.bytes {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("bytes"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.samples {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("samples"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.shards {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("shards"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct EntryRecord;
impl XrpcResp for EntryRecord {
    const NSID: &'static str = "science.alt.dataset.entry";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = EntryGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<EntryGetRecordOutput<S>> for Entry<S> {
    fn from(output: EntryGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Entry<S> {
    const NSID: &'static str = "science.alt.dataset.entry";
    type Record = EntryRecord;
}

impl Collection for EntryRecord {
    const NSID: &'static str = "science.alt.dataset.entry";
    type Record = EntryRecord;
}

impl<S: BosStr> LexiconSchema for Entry<S> {
    fn nsid() -> &'static str {
        "science.alt.dataset.entry"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_science_alt_dataset_entry()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 5000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 5000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.license {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 200usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("license"),
                    max: 200usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.metadata_schema_ref {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("metadata_schema_ref"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 200usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 200usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.schema_ref;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("schema_ref"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.tags {
            #[allow(unused_comparisons)]
            if value.len() > 30usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tags"),
                    max: 30usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ShardChecksum<S> {
    fn nsid() -> &'static str {
        "science.alt.dataset.entry"
    }
    fn def_name() -> &'static str {
        "shardChecksum"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_science_alt_dataset_entry()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.algorithm;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("algorithm"),
                    max: 20usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.digest;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("digest"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_science_alt_dataset_entry() -> 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("science.alt.dataset.entry"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("datasetSize"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Information about dataset size"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("bytes"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("samples"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("shards"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Index entry for a WebDataset-backed dataset with references to storage location and sample schema",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"),
                                SmolStr::new_static("schemaRef"),
                                SmolStr::new_static("storage"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("contentMetadata"),
                                LexObjectProperty::Unknown(LexUnknown {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp when this dataset entry was created",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Human-readable description of the dataset",
                                        ),
                                    ),
                                    max_length: Some(5000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("license"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "License identifier or URL. SPDX identifiers recommended (e.g., MIT, Apache-2.0, CC-BY-4.0) or full SPDX URLs (e.g., http://spdx.org/licenses/MIT). Aligns with Schema.org license property.",
                                        ),
                                    ),
                                    max_length: Some(200usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("metadata"),
                                LexObjectProperty::Bytes(LexBytes {
                                    max_length: Some(100000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("metadataSchemaRef"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optional AT-URI reference to a schema record defining the structure of this dataset's content metadata. When present, contentMetadata is validated against this schema at write time.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    max_length: Some(500usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Human-readable dataset name"),
                                    ),
                                    max_length: Some(200usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("schemaRef"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT-URI reference to the schema record for this dataset's samples",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    max_length: Some(500usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("size"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#datasetSize"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("storage"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "Storage location for dataset files (WebDataset tar archives)",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("science.alt.dataset.storageHttp"),
                                        CowStr::new_static("science.alt.dataset.storageS3"),
                                        CowStr::new_static("science.alt.dataset.storageBlobs")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tags"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Searchable tags for dataset discovery. Aligns with Schema.org keywords property.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        max_length: Some(150usize),
                                        ..Default::default()
                                    }),
                                    max_length: Some(30usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("shardChecksum"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Content hash for shard integrity verification. Algorithm is flexible to allow SHA-256, BLAKE3, or other hash functions.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("algorithm"),
                            SmolStr::new_static("digest")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("algorithm"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Hash algorithm identifier (e.g., 'sha256', 'blake3')",
                                    ),
                                ),
                                max_length: Some(20usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("digest"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Hex-encoded hash digest"),
                                ),
                                max_length: Some(128usize),
                                ..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 CreatedAt;
        type Name;
        type SchemaRef;
        type Storage;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Name = Unset;
        type SchemaRef = Unset;
        type Storage = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Name = St::Name;
        type SchemaRef = St::SchemaRef;
        type Storage = St::Storage;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type CreatedAt = St::CreatedAt;
        type Name = Set<members::name>;
        type SchemaRef = St::SchemaRef;
        type Storage = St::Storage;
    }
    ///State transition - sets the `schema_ref` field to Set
    pub struct SetSchemaRef<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSchemaRef<St> {}
    impl<St: State> State for SetSchemaRef<St> {
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
        type SchemaRef = Set<members::schema_ref>;
        type Storage = St::Storage;
    }
    ///State transition - sets the `storage` field to Set
    pub struct SetStorage<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStorage<St> {}
    impl<St: State> State for SetStorage<St> {
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
        type SchemaRef = St::SchemaRef;
        type Storage = Set<members::storage>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `schema_ref` field
        pub struct schema_ref(());
        ///Marker type for the `storage` field
        pub struct storage(());
    }
}

/// Builder for constructing an instance of this type.
pub struct EntryBuilder<St: entry_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Data<S>>,
        Option<Datetime>,
        Option<S>,
        Option<S>,
        Option<Bytes>,
        Option<AtUri<S>>,
        Option<S>,
        Option<AtUri<S>>,
        Option<entry::DatasetSize<S>>,
        Option<EntryStorage<S>>,
        Option<Vec<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St: entry_state::State, S: BosStr> EntryBuilder<St, S> {
    /// Set the `contentMetadata` field (optional)
    pub fn content_metadata(mut self, value: impl Into<Option<Data<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `contentMetadata` field to an Option value (optional)
    pub fn maybe_content_metadata(mut self, value: Option<Data<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: entry_state::State, S: BosStr> EntryBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: entry_state::State, S: BosStr> EntryBuilder<St, S> {
    /// Set the `license` field (optional)
    pub fn license(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `license` field to an Option value (optional)
    pub fn maybe_license(mut self, value: Option<S>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: entry_state::State, S: BosStr> EntryBuilder<St, S> {
    /// Set the `metadata` field (optional)
    pub fn metadata(mut self, value: impl Into<Option<Bytes>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `metadata` field to an Option value (optional)
    pub fn maybe_metadata(mut self, value: Option<Bytes>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: entry_state::State, S: BosStr> EntryBuilder<St, S> {
    /// Set the `metadataSchemaRef` field (optional)
    pub fn metadata_schema_ref(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `metadataSchemaRef` field to an Option value (optional)
    pub fn maybe_metadata_schema_ref(mut self, value: Option<AtUri<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

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

impl<St, S: BosStr> EntryBuilder<St, S>
where
    St: entry_state::State,
    St::SchemaRef: entry_state::IsUnset,
{
    /// Set the `schemaRef` field (required)
    pub fn schema_ref(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> EntryBuilder<entry_state::SetSchemaRef<St>, S> {
        self._fields.7 = Option::Some(value.into());
        EntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: entry_state::State, S: BosStr> EntryBuilder<St, S> {
    /// Set the `size` field (optional)
    pub fn size(mut self, value: impl Into<Option<entry::DatasetSize<S>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `size` field to an Option value (optional)
    pub fn maybe_size(mut self, value: Option<entry::DatasetSize<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St, S: BosStr> EntryBuilder<St, S>
where
    St: entry_state::State,
    St::Storage: entry_state::IsUnset,
{
    /// Set the `storage` field (required)
    pub fn storage(
        mut self,
        value: impl Into<EntryStorage<S>>,
    ) -> EntryBuilder<entry_state::SetStorage<St>, S> {
        self._fields.9 = Option::Some(value.into());
        EntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: entry_state::State, S: BosStr> EntryBuilder<St, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `tags` field to an Option value (optional)
    pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St, S: BosStr> EntryBuilder<St, S>
where
    St: entry_state::State,
    St::CreatedAt: entry_state::IsSet,
    St::Name: entry_state::IsSet,
    St::SchemaRef: entry_state::IsSet,
    St::Storage: entry_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Entry<S> {
        Entry {
            content_metadata: self._fields.0,
            created_at: self._fields.1.unwrap(),
            description: self._fields.2,
            license: self._fields.3,
            metadata: self._fields.4,
            metadata_schema_ref: self._fields.5,
            name: self._fields.6.unwrap(),
            schema_ref: self._fields.7.unwrap(),
            size: self._fields.8,
            storage: self._fields.9.unwrap(),
            tags: self._fields.10,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Entry<S> {
        Entry {
            content_metadata: self._fields.0,
            created_at: self._fields.1.unwrap(),
            description: self._fields.2,
            license: self._fields.3,
            metadata: self._fields.4,
            metadata_schema_ref: self._fields.5,
            name: self._fields.6.unwrap(),
            schema_ref: self._fields.7.unwrap(),
            size: self._fields.8,
            storage: self._fields.9.unwrap(),
            tags: self._fields.10,
            extra_data: Some(extra_data),
        }
    }
}