// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: io.atcr.manifest
//
// 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::{Did, AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
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::io_atcr::manifest;
/// Reference to a blob stored in S3 or external storage

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct BlobReference<'a> {
    ///Optional OCI annotation metadata. Map of string keys to string values.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub annotations: Option<Data<'a>>,
    ///Content digest (e.g., 'sha256:...')
    #[serde(borrow)]
    pub digest: CowStr<'a>,
    ///MIME type of the blob
    #[serde(borrow)]
    pub media_type: CowStr<'a>,
    ///Size in bytes
    pub size: i64,
    ///Optional direct URLs to blob (for BYOS)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub urls: Option<Vec<UriValue<'a>>>,
}

/// A container image manifest following OCI specification, stored in ATProto

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Manifest<'a> {
    ///Optional OCI annotation metadata. Map of string keys to string values (e.g., org.opencontainers.image.title → 'My App').
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub annotations: Option<Data<'a>>,
    ///Reference to image configuration blob
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub config: Option<manifest::BlobReference<'a>>,
    ///Record creation timestamp
    pub created_at: Datetime,
    ///Content digest (e.g., 'sha256:abc123...')
    #[serde(borrow)]
    pub digest: CowStr<'a>,
    ///DID of the hold service where blobs are stored (e.g., 'did:web:hold01.atcr.io'). Primary reference for hold resolution.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub hold_did: Option<Did<'a>>,
    ///Hold service endpoint URL where blobs are stored. DEPRECATED: Use holdDid instead. Kept for backward compatibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub hold_endpoint: Option<UriValue<'a>>,
    ///Filesystem layers (for image manifests)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub layers: Option<Vec<manifest::BlobReference<'a>>>,
    ///The full OCI manifest stored as a blob in ATProto.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub manifest_blob: Option<BlobRef<'a>>,
    ///Referenced manifests (for manifest lists/indexes)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub manifests: Option<Vec<manifest::ManifestReference<'a>>>,
    ///OCI media type
    #[serde(borrow)]
    pub media_type: ManifestMediaType<'a>,
    ///Repository name (e.g., 'myapp'). Scoped to user's DID.
    #[serde(borrow)]
    pub repository: CowStr<'a>,
    ///OCI schema version (typically 2)
    pub schema_version: i64,
    ///Optional reference to another manifest (for attestations, signatures)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub subject: Option<manifest::BlobReference<'a>>,
}

/// OCI media type

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ManifestMediaType<'a> {
    ApplicationVndOciImageManifestV1Json,
    ApplicationVndDockerDistributionManifestV2Json,
    ApplicationVndOciImageIndexV1Json,
    ApplicationVndDockerDistributionManifestListV2Json,
    Other(CowStr<'a>),
}

impl<'a> ManifestMediaType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::ApplicationVndOciImageManifestV1Json => {
                "application/vnd.oci.image.manifest.v1+json"
            }
            Self::ApplicationVndDockerDistributionManifestV2Json => {
                "application/vnd.docker.distribution.manifest.v2+json"
            }
            Self::ApplicationVndOciImageIndexV1Json => {
                "application/vnd.oci.image.index.v1+json"
            }
            Self::ApplicationVndDockerDistributionManifestListV2Json => {
                "application/vnd.docker.distribution.manifest.list.v2+json"
            }
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for ManifestMediaType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "application/vnd.oci.image.manifest.v1+json" => {
                Self::ApplicationVndOciImageManifestV1Json
            }
            "application/vnd.docker.distribution.manifest.v2+json" => {
                Self::ApplicationVndDockerDistributionManifestV2Json
            }
            "application/vnd.oci.image.index.v1+json" => {
                Self::ApplicationVndOciImageIndexV1Json
            }
            "application/vnd.docker.distribution.manifest.list.v2+json" => {
                Self::ApplicationVndDockerDistributionManifestListV2Json
            }
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ManifestMediaType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "application/vnd.oci.image.manifest.v1+json" => {
                Self::ApplicationVndOciImageManifestV1Json
            }
            "application/vnd.docker.distribution.manifest.v2+json" => {
                Self::ApplicationVndDockerDistributionManifestV2Json
            }
            "application/vnd.oci.image.index.v1+json" => {
                Self::ApplicationVndOciImageIndexV1Json
            }
            "application/vnd.docker.distribution.manifest.list.v2+json" => {
                Self::ApplicationVndDockerDistributionManifestListV2Json
            }
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for ManifestMediaType<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for ManifestMediaType<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for ManifestMediaType<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for ManifestMediaType<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for ManifestMediaType<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for ManifestMediaType<'_> {
    type Output = ManifestMediaType<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            ManifestMediaType::ApplicationVndOciImageManifestV1Json => {
                ManifestMediaType::ApplicationVndOciImageManifestV1Json
            }
            ManifestMediaType::ApplicationVndDockerDistributionManifestV2Json => {
                ManifestMediaType::ApplicationVndDockerDistributionManifestV2Json
            }
            ManifestMediaType::ApplicationVndOciImageIndexV1Json => {
                ManifestMediaType::ApplicationVndOciImageIndexV1Json
            }
            ManifestMediaType::ApplicationVndDockerDistributionManifestListV2Json => {
                ManifestMediaType::ApplicationVndDockerDistributionManifestListV2Json
            }
            ManifestMediaType::Other(v) => ManifestMediaType::Other(v.into_static()),
        }
    }
}

/// 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 ManifestGetRecordOutput<'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: Manifest<'a>,
}

/// Reference to a manifest in a manifest list/index

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ManifestReference<'a> {
    ///Optional OCI annotation metadata. Map of string keys to string values.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub annotations: Option<Data<'a>>,
    ///Content digest (e.g., 'sha256:...')
    #[serde(borrow)]
    pub digest: CowStr<'a>,
    ///Media type of the referenced manifest
    #[serde(borrow)]
    pub media_type: CowStr<'a>,
    ///Platform information for this manifest
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub platform: Option<manifest::Platform<'a>>,
    ///Size in bytes
    pub size: i64,
}

/// Platform information describing OS and architecture

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Platform<'a> {
    ///CPU architecture (e.g., 'amd64', 'arm64', 'arm')
    #[serde(borrow)]
    pub architecture: CowStr<'a>,
    ///Operating system (e.g., 'linux', 'windows', 'darwin')
    #[serde(borrow)]
    pub os: CowStr<'a>,
    ///Optional OS features
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub os_features: Option<Vec<CowStr<'a>>>,
    ///Optional OS version
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub os_version: Option<CowStr<'a>>,
    ///Optional CPU variant (e.g., 'v7' for ARM)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub variant: Option<CowStr<'a>>,
}

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

impl<'a> LexiconSchema for BlobReference<'a> {
    fn nsid() -> &'static str {
        "io.atcr.manifest"
    }
    fn def_name() -> &'static str {
        "blobReference"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_atcr_manifest()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            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()),
                });
            }
        }
        {
            let value = &self.media_type;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("media_type"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct ManifestRecord;
impl XrpcResp for ManifestRecord {
    const NSID: &'static str = "io.atcr.manifest";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ManifestGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Manifest<'_> {
    const NSID: &'static str = "io.atcr.manifest";
    type Record = ManifestRecord;
}

impl Collection for ManifestRecord {
    const NSID: &'static str = "io.atcr.manifest";
    type Record = ManifestRecord;
}

impl<'a> LexiconSchema for Manifest<'a> {
    fn nsid() -> &'static str {
        "io.atcr.manifest"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_atcr_manifest()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            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()),
                });
            }
        }
        {
            let value = &self.media_type;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("media_type"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.repository;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 255usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("repository"),
                    max: 255usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for ManifestReference<'a> {
    fn nsid() -> &'static str {
        "io.atcr.manifest"
    }
    fn def_name() -> &'static str {
        "manifestReference"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_atcr_manifest()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            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()),
                });
            }
        }
        {
            let value = &self.media_type;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("media_type"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Platform<'a> {
    fn nsid() -> &'static str {
        "io.atcr.manifest"
    }
    fn def_name() -> &'static str {
        "platform"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_atcr_manifest()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.architecture;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("architecture"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.os;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("os"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.os_version {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 64usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("os_version"),
                    max: 64usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.variant {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("variant"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod blob_reference_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 MediaType;
        type Size;
        type Digest;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type MediaType = Unset;
        type Size = Unset;
        type Digest = Unset;
    }
    ///State transition - sets the `media_type` field to Set
    pub struct SetMediaType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMediaType<S> {}
    impl<S: State> State for SetMediaType<S> {
        type MediaType = Set<members::media_type>;
        type Size = S::Size;
        type Digest = S::Digest;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSize<S> {}
    impl<S: State> State for SetSize<S> {
        type MediaType = S::MediaType;
        type Size = Set<members::size>;
        type Digest = S::Digest;
    }
    ///State transition - sets the `digest` field to Set
    pub struct SetDigest<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDigest<S> {}
    impl<S: State> State for SetDigest<S> {
        type MediaType = S::MediaType;
        type Size = S::Size;
        type Digest = Set<members::digest>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `media_type` field
        pub struct media_type(());
        ///Marker type for the `size` field
        pub struct size(());
        ///Marker type for the `digest` field
        pub struct digest(());
    }
}

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

impl<'a> BlobReference<'a> {
    /// Create a new builder for this type
    pub fn new() -> BlobReferenceBuilder<'a, blob_reference_state::Empty> {
        BlobReferenceBuilder::new()
    }
}

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

impl<'a, S: blob_reference_state::State> BlobReferenceBuilder<'a, S> {
    /// Set the `annotations` field (optional)
    pub fn annotations(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `annotations` field to an Option value (optional)
    pub fn maybe_annotations(mut self, value: Option<Data<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<'a, S> BlobReferenceBuilder<'a, S>
where
    S: blob_reference_state::State,
    S::MediaType: blob_reference_state::IsUnset,
{
    /// Set the `mediaType` field (required)
    pub fn media_type(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> BlobReferenceBuilder<'a, blob_reference_state::SetMediaType<S>> {
        self._fields.2 = Option::Some(value.into());
        BlobReferenceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S: blob_reference_state::State> BlobReferenceBuilder<'a, S> {
    /// Set the `urls` field (optional)
    pub fn urls(mut self, value: impl Into<Option<Vec<UriValue<'a>>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `urls` field to an Option value (optional)
    pub fn maybe_urls(mut self, value: Option<Vec<UriValue<'a>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> BlobReferenceBuilder<'a, S>
where
    S: blob_reference_state::State,
    S::MediaType: blob_reference_state::IsSet,
    S::Size: blob_reference_state::IsSet,
    S::Digest: blob_reference_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> BlobReference<'a> {
        BlobReference {
            annotations: self._fields.0,
            digest: self._fields.1.unwrap(),
            media_type: self._fields.2.unwrap(),
            size: self._fields.3.unwrap(),
            urls: self._fields.4,
            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, Data<'a>>,
    ) -> BlobReference<'a> {
        BlobReference {
            annotations: self._fields.0,
            digest: self._fields.1.unwrap(),
            media_type: self._fields.2.unwrap(),
            size: self._fields.3.unwrap(),
            urls: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_io_atcr_manifest() -> 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("io.atcr.manifest"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("blobReference"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Reference to a blob stored in S3 or external storage",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("mediaType"),
                            SmolStr::new_static("size"), SmolStr::new_static("digest")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("annotations"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("digest"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Content digest (e.g., 'sha256:...')"),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("mediaType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("MIME type of the blob"),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("size"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("urls"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional direct URLs to blob (for BYOS)",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A container image manifest following OCI specification, stored in ATProto",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("repository"),
                                SmolStr::new_static("digest"),
                                SmolStr::new_static("mediaType"),
                                SmolStr::new_static("schemaVersion"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("annotations"),
                                LexObjectProperty::Unknown(LexUnknown {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("config"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#blobReference"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Record creation timestamp"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("digest"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Content digest (e.g., 'sha256:abc123...')",
                                        ),
                                    ),
                                    max_length: Some(128usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("holdDid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "DID of the hold service where blobs are stored (e.g., 'did:web:hold01.atcr.io'). Primary reference for hold resolution.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("holdEndpoint"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Hold service endpoint URL where blobs are stored. DEPRECATED: Use holdDid instead. Kept for backward compatibility.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("layers"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Filesystem layers (for image manifests)",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#blobReference"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("manifestBlob"),
                                LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                            );
                            map.insert(
                                SmolStr::new_static("manifests"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Referenced manifests (for manifest lists/indexes)",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#manifestReference"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("mediaType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("OCI media type")),
                                    max_length: Some(128usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("repository"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Repository name (e.g., 'myapp'). Scoped to user's DID.",
                                        ),
                                    ),
                                    max_length: Some(255usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("schemaVersion"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("subject"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#blobReference"),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("manifestReference"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Reference to a manifest in a manifest list/index",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("mediaType"),
                            SmolStr::new_static("size"), SmolStr::new_static("digest")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("annotations"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("digest"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Content digest (e.g., 'sha256:...')"),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("mediaType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Media type of the referenced manifest"),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("platform"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#platform"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("size"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("platform"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Platform information describing OS and architecture",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("architecture"),
                            SmolStr::new_static("os")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("architecture"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "CPU architecture (e.g., 'amd64', 'arm64', 'arm')",
                                    ),
                                ),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("os"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Operating system (e.g., 'linux', 'windows', 'darwin')",
                                    ),
                                ),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("osFeatures"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("Optional OS features"),
                                ),
                                items: LexArrayItem::String(LexString {
                                    max_length: Some(64usize),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("osVersion"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Optional OS version"),
                                ),
                                max_length: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("variant"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional CPU variant (e.g., 'v7' for ARM)",
                                    ),
                                ),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod manifest_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 Digest;
        type SchemaVersion;
        type MediaType;
        type CreatedAt;
        type Repository;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Digest = Unset;
        type SchemaVersion = Unset;
        type MediaType = Unset;
        type CreatedAt = Unset;
        type Repository = Unset;
    }
    ///State transition - sets the `digest` field to Set
    pub struct SetDigest<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDigest<S> {}
    impl<S: State> State for SetDigest<S> {
        type Digest = Set<members::digest>;
        type SchemaVersion = S::SchemaVersion;
        type MediaType = S::MediaType;
        type CreatedAt = S::CreatedAt;
        type Repository = S::Repository;
    }
    ///State transition - sets the `schema_version` field to Set
    pub struct SetSchemaVersion<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSchemaVersion<S> {}
    impl<S: State> State for SetSchemaVersion<S> {
        type Digest = S::Digest;
        type SchemaVersion = Set<members::schema_version>;
        type MediaType = S::MediaType;
        type CreatedAt = S::CreatedAt;
        type Repository = S::Repository;
    }
    ///State transition - sets the `media_type` field to Set
    pub struct SetMediaType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMediaType<S> {}
    impl<S: State> State for SetMediaType<S> {
        type Digest = S::Digest;
        type SchemaVersion = S::SchemaVersion;
        type MediaType = Set<members::media_type>;
        type CreatedAt = S::CreatedAt;
        type Repository = S::Repository;
    }
    ///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 Digest = S::Digest;
        type SchemaVersion = S::SchemaVersion;
        type MediaType = S::MediaType;
        type CreatedAt = Set<members::created_at>;
        type Repository = S::Repository;
    }
    ///State transition - sets the `repository` field to Set
    pub struct SetRepository<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRepository<S> {}
    impl<S: State> State for SetRepository<S> {
        type Digest = S::Digest;
        type SchemaVersion = S::SchemaVersion;
        type MediaType = S::MediaType;
        type CreatedAt = S::CreatedAt;
        type Repository = Set<members::repository>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `digest` field
        pub struct digest(());
        ///Marker type for the `schema_version` field
        pub struct schema_version(());
        ///Marker type for the `media_type` field
        pub struct media_type(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `repository` field
        pub struct repository(());
    }
}

/// Builder for constructing an instance of this type
pub struct ManifestBuilder<'a, S: manifest_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Data<'a>>,
        Option<manifest::BlobReference<'a>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<Did<'a>>,
        Option<UriValue<'a>>,
        Option<Vec<manifest::BlobReference<'a>>>,
        Option<BlobRef<'a>>,
        Option<Vec<manifest::ManifestReference<'a>>>,
        Option<ManifestMediaType<'a>>,
        Option<CowStr<'a>>,
        Option<i64>,
        Option<manifest::BlobReference<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Manifest<'a> {
    /// Create a new builder for this type
    pub fn new() -> ManifestBuilder<'a, manifest_state::Empty> {
        ManifestBuilder::new()
    }
}

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

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `annotations` field (optional)
    pub fn annotations(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `annotations` field to an Option value (optional)
    pub fn maybe_annotations(mut self, value: Option<Data<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `config` field (optional)
    pub fn config(
        mut self,
        value: impl Into<Option<manifest::BlobReference<'a>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `config` field to an Option value (optional)
    pub fn maybe_config(mut self, value: Option<manifest::BlobReference<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `holdDid` field (optional)
    pub fn hold_did(mut self, value: impl Into<Option<Did<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `holdDid` field to an Option value (optional)
    pub fn maybe_hold_did(mut self, value: Option<Did<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `holdEndpoint` field (optional)
    pub fn hold_endpoint(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `holdEndpoint` field to an Option value (optional)
    pub fn maybe_hold_endpoint(mut self, value: Option<UriValue<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `layers` field (optional)
    pub fn layers(
        mut self,
        value: impl Into<Option<Vec<manifest::BlobReference<'a>>>>,
    ) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `layers` field to an Option value (optional)
    pub fn maybe_layers(
        mut self,
        value: Option<Vec<manifest::BlobReference<'a>>>,
    ) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `manifestBlob` field (optional)
    pub fn manifest_blob(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `manifestBlob` field to an Option value (optional)
    pub fn maybe_manifest_blob(mut self, value: Option<BlobRef<'a>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `manifests` field (optional)
    pub fn manifests(
        mut self,
        value: impl Into<Option<Vec<manifest::ManifestReference<'a>>>>,
    ) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `manifests` field to an Option value (optional)
    pub fn maybe_manifests(
        mut self,
        value: Option<Vec<manifest::ManifestReference<'a>>>,
    ) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<'a, S> ManifestBuilder<'a, S>
where
    S: manifest_state::State,
    S::MediaType: manifest_state::IsUnset,
{
    /// Set the `mediaType` field (required)
    pub fn media_type(
        mut self,
        value: impl Into<ManifestMediaType<'a>>,
    ) -> ManifestBuilder<'a, manifest_state::SetMediaType<S>> {
        self._fields.9 = Option::Some(value.into());
        ManifestBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ManifestBuilder<'a, S>
where
    S: manifest_state::State,
    S::Repository: manifest_state::IsUnset,
{
    /// Set the `repository` field (required)
    pub fn repository(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> ManifestBuilder<'a, manifest_state::SetRepository<S>> {
        self._fields.10 = Option::Some(value.into());
        ManifestBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ManifestBuilder<'a, S>
where
    S: manifest_state::State,
    S::SchemaVersion: manifest_state::IsUnset,
{
    /// Set the `schemaVersion` field (required)
    pub fn schema_version(
        mut self,
        value: impl Into<i64>,
    ) -> ManifestBuilder<'a, manifest_state::SetSchemaVersion<S>> {
        self._fields.11 = Option::Some(value.into());
        ManifestBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: manifest_state::State> ManifestBuilder<'a, S> {
    /// Set the `subject` field (optional)
    pub fn subject(
        mut self,
        value: impl Into<Option<manifest::BlobReference<'a>>>,
    ) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `subject` field to an Option value (optional)
    pub fn maybe_subject(mut self, value: Option<manifest::BlobReference<'a>>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<'a, S> ManifestBuilder<'a, S>
where
    S: manifest_state::State,
    S::Digest: manifest_state::IsSet,
    S::SchemaVersion: manifest_state::IsSet,
    S::MediaType: manifest_state::IsSet,
    S::CreatedAt: manifest_state::IsSet,
    S::Repository: manifest_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Manifest<'a> {
        Manifest {
            annotations: self._fields.0,
            config: self._fields.1,
            created_at: self._fields.2.unwrap(),
            digest: self._fields.3.unwrap(),
            hold_did: self._fields.4,
            hold_endpoint: self._fields.5,
            layers: self._fields.6,
            manifest_blob: self._fields.7,
            manifests: self._fields.8,
            media_type: self._fields.9.unwrap(),
            repository: self._fields.10.unwrap(),
            schema_version: self._fields.11.unwrap(),
            subject: self._fields.12,
            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, Data<'a>>,
    ) -> Manifest<'a> {
        Manifest {
            annotations: self._fields.0,
            config: self._fields.1,
            created_at: self._fields.2.unwrap(),
            digest: self._fields.3.unwrap(),
            hold_did: self._fields.4,
            hold_endpoint: self._fields.5,
            layers: self._fields.6,
            manifest_blob: self._fields.7,
            manifests: self._fields.8,
            media_type: self._fields.9.unwrap(),
            repository: self._fields.10.unwrap(),
            schema_version: self._fields.11.unwrap(),
            subject: self._fields.12,
            extra_data: Some(extra_data),
        }
    }
}

pub mod manifest_reference_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 Digest;
        type Size;
        type MediaType;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Digest = Unset;
        type Size = Unset;
        type MediaType = Unset;
    }
    ///State transition - sets the `digest` field to Set
    pub struct SetDigest<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDigest<S> {}
    impl<S: State> State for SetDigest<S> {
        type Digest = Set<members::digest>;
        type Size = S::Size;
        type MediaType = S::MediaType;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSize<S> {}
    impl<S: State> State for SetSize<S> {
        type Digest = S::Digest;
        type Size = Set<members::size>;
        type MediaType = S::MediaType;
    }
    ///State transition - sets the `media_type` field to Set
    pub struct SetMediaType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMediaType<S> {}
    impl<S: State> State for SetMediaType<S> {
        type Digest = S::Digest;
        type Size = S::Size;
        type MediaType = Set<members::media_type>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `digest` field
        pub struct digest(());
        ///Marker type for the `size` field
        pub struct size(());
        ///Marker type for the `media_type` field
        pub struct media_type(());
    }
}

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

impl<'a> ManifestReference<'a> {
    /// Create a new builder for this type
    pub fn new() -> ManifestReferenceBuilder<'a, manifest_reference_state::Empty> {
        ManifestReferenceBuilder::new()
    }
}

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

impl<'a, S: manifest_reference_state::State> ManifestReferenceBuilder<'a, S> {
    /// Set the `annotations` field (optional)
    pub fn annotations(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `annotations` field to an Option value (optional)
    pub fn maybe_annotations(mut self, value: Option<Data<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<'a, S> ManifestReferenceBuilder<'a, S>
where
    S: manifest_reference_state::State,
    S::MediaType: manifest_reference_state::IsUnset,
{
    /// Set the `mediaType` field (required)
    pub fn media_type(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> ManifestReferenceBuilder<'a, manifest_reference_state::SetMediaType<S>> {
        self._fields.2 = Option::Some(value.into());
        ManifestReferenceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: manifest_reference_state::State> ManifestReferenceBuilder<'a, S> {
    /// Set the `platform` field (optional)
    pub fn platform(mut self, value: impl Into<Option<manifest::Platform<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `platform` field to an Option value (optional)
    pub fn maybe_platform(mut self, value: Option<manifest::Platform<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<'a, S> ManifestReferenceBuilder<'a, S>
where
    S: manifest_reference_state::State,
    S::Digest: manifest_reference_state::IsSet,
    S::Size: manifest_reference_state::IsSet,
    S::MediaType: manifest_reference_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ManifestReference<'a> {
        ManifestReference {
            annotations: self._fields.0,
            digest: self._fields.1.unwrap(),
            media_type: self._fields.2.unwrap(),
            platform: self._fields.3,
            size: 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, Data<'a>>,
    ) -> ManifestReference<'a> {
        ManifestReference {
            annotations: self._fields.0,
            digest: self._fields.1.unwrap(),
            media_type: self._fields.2.unwrap(),
            platform: self._fields.3,
            size: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}