// @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, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
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

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

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "io.atcr.manifest",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Manifest<S: BosStr = DefaultStr> {
    ///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")]
    pub annotations: Option<Data<S>>,
    ///Reference to image configuration blob
    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<manifest::BlobReference<S>>,
    ///Record creation timestamp
    pub created_at: Datetime,
    ///Content digest (e.g., 'sha256:abc123...')
    pub digest: S,
    ///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")]
    pub hold_did: Option<Did<S>>,
    ///Hold service endpoint URL where blobs are stored. DEPRECATED: Use holdDid instead. Kept for backward compatibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hold_endpoint: Option<UriValue<S>>,
    ///Filesystem layers (for image manifests)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub layers: Option<Vec<manifest::BlobReference<S>>>,
    ///The full OCI manifest stored as a blob in ATProto.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manifest_blob: Option<BlobRef<S>>,
    ///Referenced manifests (for manifest lists/indexes)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manifests: Option<Vec<manifest::ManifestReference<S>>>,
    ///OCI media type
    pub media_type: ManifestMediaType<S>,
    ///Repository name (e.g., 'myapp'). Scoped to user's DID.
    pub repository: S,
    ///OCI schema version (typically 2)
    pub schema_version: i64,
    ///Optional reference to another manifest (for attestations, signatures)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject: Option<manifest::BlobReference<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// OCI media type

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ManifestMediaType<S: BosStr = DefaultStr> {
    ApplicationVndOciImageManifestV1Json,
    ApplicationVndDockerDistributionManifestV2Json,
    ApplicationVndOciImageIndexV1Json,
    ApplicationVndDockerDistributionManifestListV2Json,
    Other(S),
}

impl<S: BosStr> ManifestMediaType<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "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(s),
        }
    }
}

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

impl<S: BosStr> AsRef<str> for ManifestMediaType<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ManifestMediaType<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for ManifestMediaType<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ManifestMediaType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ManifestMediaType<S::Output>;
    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<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Manifest<S>,
}

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

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

/// Platform information describing OS and architecture

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Platform<S: BosStr = DefaultStr> {
    ///CPU architecture (e.g., 'amd64', 'arm64', 'arm')
    pub architecture: S,
    ///Operating system (e.g., 'linux', 'windows', 'darwin')
    pub os: S,
    ///Optional OS features
    #[serde(skip_serializing_if = "Option::is_none")]
    pub os_features: Option<Vec<S>>,
    ///Optional OS version
    #[serde(skip_serializing_if = "Option::is_none")]
    pub os_version: Option<S>,
    ///Optional CPU variant (e.g., 'v7' for ARM)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub variant: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

impl<S: BosStr> LexiconSchema for BlobReference<S> {
    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<S: BosStr> = ManifestGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Manifest<S> {
    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<S: BosStr> LexiconSchema for Manifest<S> {
    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<S: BosStr> LexiconSchema for ManifestReference<S> {
    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<S: BosStr> LexiconSchema for Platform<S> {
    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 Digest;
        type MediaType;
        type Size;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Digest = Unset;
        type MediaType = Unset;
        type Size = Unset;
    }
    ///State transition - sets the `digest` field to Set
    pub struct SetDigest<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDigest<St> {}
    impl<St: State> State for SetDigest<St> {
        type Digest = Set<members::digest>;
        type MediaType = St::MediaType;
        type Size = St::Size;
    }
    ///State transition - sets the `media_type` field to Set
    pub struct SetMediaType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMediaType<St> {}
    impl<St: State> State for SetMediaType<St> {
        type Digest = St::Digest;
        type MediaType = Set<members::media_type>;
        type Size = St::Size;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSize<St> {}
    impl<St: State> State for SetSize<St> {
        type Digest = St::Digest;
        type MediaType = St::MediaType;
        type Size = Set<members::size>;
    }
    /// 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 `media_type` field
        pub struct media_type(());
        ///Marker type for the `size` field
        pub struct size(());
    }
}

/// Builder for constructing an instance of this type.
pub struct BlobReferenceBuilder<
    St: blob_reference_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Data<S>>,
        Option<S>,
        Option<S>,
        Option<i64>,
        Option<Vec<UriValue<S>>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St: blob_reference_state::State, S: BosStr> BlobReferenceBuilder<St, S> {
    /// Set the `annotations` field (optional)
    pub fn annotations(mut self, value: impl Into<Option<Data<S>>>) -> 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<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

impl<St: blob_reference_state::State, S: BosStr> BlobReferenceBuilder<St, S> {
    /// Set the `urls` field (optional)
    pub fn urls(mut self, value: impl Into<Option<Vec<UriValue<S>>>>) -> 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<S>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> BlobReferenceBuilder<St, S>
where
    St: blob_reference_state::State,
    St::Digest: blob_reference_state::IsSet,
    St::MediaType: blob_reference_state::IsSet,
    St::Size: blob_reference_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> BlobReference<S> {
        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<SmolStr, Data<S>>,
    ) -> BlobReference<S> {
        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 CreatedAt;
        type Digest;
        type MediaType;
        type Repository;
        type SchemaVersion;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Digest = Unset;
        type MediaType = Unset;
        type Repository = Unset;
        type SchemaVersion = 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 Digest = St::Digest;
        type MediaType = St::MediaType;
        type Repository = St::Repository;
        type SchemaVersion = St::SchemaVersion;
    }
    ///State transition - sets the `digest` field to Set
    pub struct SetDigest<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDigest<St> {}
    impl<St: State> State for SetDigest<St> {
        type CreatedAt = St::CreatedAt;
        type Digest = Set<members::digest>;
        type MediaType = St::MediaType;
        type Repository = St::Repository;
        type SchemaVersion = St::SchemaVersion;
    }
    ///State transition - sets the `media_type` field to Set
    pub struct SetMediaType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMediaType<St> {}
    impl<St: State> State for SetMediaType<St> {
        type CreatedAt = St::CreatedAt;
        type Digest = St::Digest;
        type MediaType = Set<members::media_type>;
        type Repository = St::Repository;
        type SchemaVersion = St::SchemaVersion;
    }
    ///State transition - sets the `repository` field to Set
    pub struct SetRepository<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRepository<St> {}
    impl<St: State> State for SetRepository<St> {
        type CreatedAt = St::CreatedAt;
        type Digest = St::Digest;
        type MediaType = St::MediaType;
        type Repository = Set<members::repository>;
        type SchemaVersion = St::SchemaVersion;
    }
    ///State transition - sets the `schema_version` field to Set
    pub struct SetSchemaVersion<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSchemaVersion<St> {}
    impl<St: State> State for SetSchemaVersion<St> {
        type CreatedAt = St::CreatedAt;
        type Digest = St::Digest;
        type MediaType = St::MediaType;
        type Repository = St::Repository;
        type SchemaVersion = Set<members::schema_version>;
    }
    /// 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 `digest` field
        pub struct digest(());
        ///Marker type for the `media_type` field
        pub struct media_type(());
        ///Marker type for the `repository` field
        pub struct repository(());
        ///Marker type for the `schema_version` field
        pub struct schema_version(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ManifestBuilder<St: manifest_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Data<S>>,
        Option<manifest::BlobReference<S>>,
        Option<Datetime>,
        Option<S>,
        Option<Did<S>>,
        Option<UriValue<S>>,
        Option<Vec<manifest::BlobReference<S>>>,
        Option<BlobRef<S>>,
        Option<Vec<manifest::ManifestReference<S>>>,
        Option<ManifestMediaType<S>>,
        Option<S>,
        Option<i64>,
        Option<manifest::BlobReference<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `annotations` field (optional)
    pub fn annotations(mut self, value: impl Into<Option<Data<S>>>) -> 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<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `config` field (optional)
    pub fn config(
        mut self,
        value: impl Into<Option<manifest::BlobReference<S>>>,
    ) -> 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<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `holdDid` field (optional)
    pub fn hold_did(mut self, value: impl Into<Option<Did<S>>>) -> 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<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `holdEndpoint` field (optional)
    pub fn hold_endpoint(mut self, value: impl Into<Option<UriValue<S>>>) -> 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<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `layers` field (optional)
    pub fn layers(
        mut self,
        value: impl Into<Option<Vec<manifest::BlobReference<S>>>>,
    ) -> 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<S>>>,
    ) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `manifestBlob` field (optional)
    pub fn manifest_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> 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<S>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `manifests` field (optional)
    pub fn manifests(
        mut self,
        value: impl Into<Option<Vec<manifest::ManifestReference<S>>>>,
    ) -> 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<S>>>,
    ) -> Self {
        self._fields.8 = value;
        self
    }
}

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

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

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

impl<St: manifest_state::State, S: BosStr> ManifestBuilder<St, S> {
    /// Set the `subject` field (optional)
    pub fn subject(
        mut self,
        value: impl Into<Option<manifest::BlobReference<S>>>,
    ) -> 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<S>>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<St, S: BosStr> ManifestBuilder<St, S>
where
    St: manifest_state::State,
    St::CreatedAt: manifest_state::IsSet,
    St::Digest: manifest_state::IsSet,
    St::MediaType: manifest_state::IsSet,
    St::Repository: manifest_state::IsSet,
    St::SchemaVersion: manifest_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Manifest<S> {
        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<SmolStr, Data<S>>) -> Manifest<S> {
        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 MediaType;
        type Size;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Digest = Unset;
        type MediaType = Unset;
        type Size = Unset;
    }
    ///State transition - sets the `digest` field to Set
    pub struct SetDigest<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDigest<St> {}
    impl<St: State> State for SetDigest<St> {
        type Digest = Set<members::digest>;
        type MediaType = St::MediaType;
        type Size = St::Size;
    }
    ///State transition - sets the `media_type` field to Set
    pub struct SetMediaType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMediaType<St> {}
    impl<St: State> State for SetMediaType<St> {
        type Digest = St::Digest;
        type MediaType = Set<members::media_type>;
        type Size = St::Size;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSize<St> {}
    impl<St: State> State for SetSize<St> {
        type Digest = St::Digest;
        type MediaType = St::MediaType;
        type Size = Set<members::size>;
    }
    /// 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 `media_type` field
        pub struct media_type(());
        ///Marker type for the `size` field
        pub struct size(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ManifestReferenceBuilder<
    St: manifest_reference_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Data<S>>,
        Option<S>,
        Option<S>,
        Option<manifest::Platform<S>>,
        Option<i64>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St: manifest_reference_state::State, S: BosStr> ManifestReferenceBuilder<St, S> {
    /// Set the `annotations` field (optional)
    pub fn annotations(mut self, value: impl Into<Option<Data<S>>>) -> 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<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

impl<St: manifest_reference_state::State, S: BosStr> ManifestReferenceBuilder<St, S> {
    /// Set the `platform` field (optional)
    pub fn platform(mut self, value: impl Into<Option<manifest::Platform<S>>>) -> 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<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<St, S: BosStr> ManifestReferenceBuilder<St, S>
where
    St: manifest_reference_state::State,
    St::Digest: manifest_reference_state::IsSet,
    St::MediaType: manifest_reference_state::IsSet,
    St::Size: manifest_reference_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ManifestReference<S> {
        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<SmolStr, Data<S>>,
    ) -> ManifestReference<S> {
        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),
        }
    }
}