// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: io.atcr.hold.scan
//
// 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};
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};
/// Vulnerability scan results for a container manifest. Stored in the hold's embedded PDS. Record key is deterministic: the manifest digest hex without the 'sha256:' prefix, so re-scans upsert the existing record.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "io.atcr.hold.scan",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Scan<S: BosStr = DefaultStr> {
    ///Count of critical severity vulnerabilities
    pub critical: i64,
    ///Count of high severity vulnerabilities
    pub high: i64,
    ///Count of low severity vulnerabilities
    pub low: i64,
    ///AT-URI of the scanned manifest (e.g., at://did:plc:xyz/io.atcr.manifest/abc123...)
    pub manifest: AtUri<S>,
    ///Count of medium severity vulnerabilities
    pub medium: i64,
    ///Repository name (e.g., myapp)
    pub repository: S,
    ///SBOM blob (SPDX JSON format) uploaded to the hold's blob storage
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sbom_blob: Option<BlobRef<S>>,
    ///RFC3339 timestamp of when the scan completed
    pub scanned_at: Datetime,
    ///Version of the scanner that produced this result (e.g., atcr-scanner-v1.0.0)
    pub scanner_version: S,
    ///Total vulnerability count
    pub total: i64,
    ///DID of the image owner
    pub user_did: Did<S>,
    ///Grype vulnerability report blob (JSON) with full CVE details
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vuln_report_blob: Option<BlobRef<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ScanGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Scan<S>,
}

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

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

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

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

impl<S: BosStr> Collection for Scan<S> {
    const NSID: &'static str = "io.atcr.hold.scan";
    type Record = ScanRecord;
}

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

impl<S: BosStr> LexiconSchema for Scan<S> {
    fn nsid() -> &'static str {
        "io.atcr.hold.scan"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_atcr_hold_scan()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.critical;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("critical"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.high;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("high"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.low;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("low"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.medium;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("medium"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.repository;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("repository"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.sbom_blob {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["application/spdx+json"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("sbom_blob"),
                        accepted: vec!["application/spdx+json".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        {
            let value = &self.scanner_version;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 64usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("scanner_version"),
                    max: 64usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.total;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("total"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.vuln_report_blob {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["application/vnd.atcr.vulnerabilities+json"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("vuln_report_blob"),
                        accepted: vec![
                            "application/vnd.atcr.vulnerabilities+json".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod scan_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 Critical;
        type High;
        type Low;
        type Manifest;
        type Medium;
        type Repository;
        type ScannedAt;
        type ScannerVersion;
        type Total;
        type UserDid;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Critical = Unset;
        type High = Unset;
        type Low = Unset;
        type Manifest = Unset;
        type Medium = Unset;
        type Repository = Unset;
        type ScannedAt = Unset;
        type ScannerVersion = Unset;
        type Total = Unset;
        type UserDid = Unset;
    }
    ///State transition - sets the `critical` field to Set
    pub struct SetCritical<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCritical<St> {}
    impl<St: State> State for SetCritical<St> {
        type Critical = Set<members::critical>;
        type High = St::High;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `high` field to Set
    pub struct SetHigh<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHigh<St> {}
    impl<St: State> State for SetHigh<St> {
        type Critical = St::Critical;
        type High = Set<members::high>;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `low` field to Set
    pub struct SetLow<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLow<St> {}
    impl<St: State> State for SetLow<St> {
        type Critical = St::Critical;
        type High = St::High;
        type Low = Set<members::low>;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `manifest` field to Set
    pub struct SetManifest<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetManifest<St> {}
    impl<St: State> State for SetManifest<St> {
        type Critical = St::Critical;
        type High = St::High;
        type Low = St::Low;
        type Manifest = Set<members::manifest>;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `medium` field to Set
    pub struct SetMedium<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMedium<St> {}
    impl<St: State> State for SetMedium<St> {
        type Critical = St::Critical;
        type High = St::High;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = Set<members::medium>;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///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 Critical = St::Critical;
        type High = St::High;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = Set<members::repository>;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `scanned_at` field to Set
    pub struct SetScannedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetScannedAt<St> {}
    impl<St: State> State for SetScannedAt<St> {
        type Critical = St::Critical;
        type High = St::High;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = Set<members::scanned_at>;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `scanner_version` field to Set
    pub struct SetScannerVersion<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetScannerVersion<St> {}
    impl<St: State> State for SetScannerVersion<St> {
        type Critical = St::Critical;
        type High = St::High;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = Set<members::scanner_version>;
        type Total = St::Total;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `total` field to Set
    pub struct SetTotal<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTotal<St> {}
    impl<St: State> State for SetTotal<St> {
        type Critical = St::Critical;
        type High = St::High;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = Set<members::total>;
        type UserDid = St::UserDid;
    }
    ///State transition - sets the `user_did` field to Set
    pub struct SetUserDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUserDid<St> {}
    impl<St: State> State for SetUserDid<St> {
        type Critical = St::Critical;
        type High = St::High;
        type Low = St::Low;
        type Manifest = St::Manifest;
        type Medium = St::Medium;
        type Repository = St::Repository;
        type ScannedAt = St::ScannedAt;
        type ScannerVersion = St::ScannerVersion;
        type Total = St::Total;
        type UserDid = Set<members::user_did>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `critical` field
        pub struct critical(());
        ///Marker type for the `high` field
        pub struct high(());
        ///Marker type for the `low` field
        pub struct low(());
        ///Marker type for the `manifest` field
        pub struct manifest(());
        ///Marker type for the `medium` field
        pub struct medium(());
        ///Marker type for the `repository` field
        pub struct repository(());
        ///Marker type for the `scanned_at` field
        pub struct scanned_at(());
        ///Marker type for the `scanner_version` field
        pub struct scanner_version(());
        ///Marker type for the `total` field
        pub struct total(());
        ///Marker type for the `user_did` field
        pub struct user_did(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ScanBuilder<St: scan_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<i64>,
        Option<i64>,
        Option<i64>,
        Option<AtUri<S>>,
        Option<i64>,
        Option<S>,
        Option<BlobRef<S>>,
        Option<Datetime>,
        Option<S>,
        Option<i64>,
        Option<Did<S>>,
        Option<BlobRef<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Scan<S> {
    /// Create a new builder for this type
    pub fn builder() -> ScanBuilder<scan_state::Empty, S> {
        ScanBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::Critical: scan_state::IsUnset,
{
    /// Set the `critical` field (required)
    pub fn critical(
        mut self,
        value: impl Into<i64>,
    ) -> ScanBuilder<scan_state::SetCritical<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::High: scan_state::IsUnset,
{
    /// Set the `high` field (required)
    pub fn high(
        mut self,
        value: impl Into<i64>,
    ) -> ScanBuilder<scan_state::SetHigh<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::Low: scan_state::IsUnset,
{
    /// Set the `low` field (required)
    pub fn low(
        mut self,
        value: impl Into<i64>,
    ) -> ScanBuilder<scan_state::SetLow<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::Manifest: scan_state::IsUnset,
{
    /// Set the `manifest` field (required)
    pub fn manifest(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ScanBuilder<scan_state::SetManifest<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St: scan_state::State, S: BosStr> ScanBuilder<St, S> {
    /// Set the `sbomBlob` field (optional)
    pub fn sbom_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `sbomBlob` field to an Option value (optional)
    pub fn maybe_sbom_blob(mut self, value: Option<BlobRef<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::ScannedAt: scan_state::IsUnset,
{
    /// Set the `scannedAt` field (required)
    pub fn scanned_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> ScanBuilder<scan_state::SetScannedAt<St>, S> {
        self._fields.7 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::ScannerVersion: scan_state::IsUnset,
{
    /// Set the `scannerVersion` field (required)
    pub fn scanner_version(
        mut self,
        value: impl Into<S>,
    ) -> ScanBuilder<scan_state::SetScannerVersion<St>, S> {
        self._fields.8 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::Total: scan_state::IsUnset,
{
    /// Set the `total` field (required)
    pub fn total(
        mut self,
        value: impl Into<i64>,
    ) -> ScanBuilder<scan_state::SetTotal<St>, S> {
        self._fields.9 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::UserDid: scan_state::IsUnset,
{
    /// Set the `userDid` field (required)
    pub fn user_did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ScanBuilder<scan_state::SetUserDid<St>, S> {
        self._fields.10 = Option::Some(value.into());
        ScanBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: scan_state::State, S: BosStr> ScanBuilder<St, S> {
    /// Set the `vulnReportBlob` field (optional)
    pub fn vuln_report_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `vulnReportBlob` field to an Option value (optional)
    pub fn maybe_vuln_report_blob(mut self, value: Option<BlobRef<S>>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<St, S: BosStr> ScanBuilder<St, S>
where
    St: scan_state::State,
    St::Critical: scan_state::IsSet,
    St::High: scan_state::IsSet,
    St::Low: scan_state::IsSet,
    St::Manifest: scan_state::IsSet,
    St::Medium: scan_state::IsSet,
    St::Repository: scan_state::IsSet,
    St::ScannedAt: scan_state::IsSet,
    St::ScannerVersion: scan_state::IsSet,
    St::Total: scan_state::IsSet,
    St::UserDid: scan_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Scan<S> {
        Scan {
            critical: self._fields.0.unwrap(),
            high: self._fields.1.unwrap(),
            low: self._fields.2.unwrap(),
            manifest: self._fields.3.unwrap(),
            medium: self._fields.4.unwrap(),
            repository: self._fields.5.unwrap(),
            sbom_blob: self._fields.6,
            scanned_at: self._fields.7.unwrap(),
            scanner_version: self._fields.8.unwrap(),
            total: self._fields.9.unwrap(),
            user_did: self._fields.10.unwrap(),
            vuln_report_blob: self._fields.11,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Scan<S> {
        Scan {
            critical: self._fields.0.unwrap(),
            high: self._fields.1.unwrap(),
            low: self._fields.2.unwrap(),
            manifest: self._fields.3.unwrap(),
            medium: self._fields.4.unwrap(),
            repository: self._fields.5.unwrap(),
            sbom_blob: self._fields.6,
            scanned_at: self._fields.7.unwrap(),
            scanner_version: self._fields.8.unwrap(),
            total: self._fields.9.unwrap(),
            user_did: self._fields.10.unwrap(),
            vuln_report_blob: self._fields.11,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_io_atcr_hold_scan() -> 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.hold.scan"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Vulnerability scan results for a container manifest. Stored in the hold's embedded PDS. Record key is deterministic: the manifest digest hex without the 'sha256:' prefix, so re-scans upsert the existing record.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("manifest"),
                                SmolStr::new_static("repository"),
                                SmolStr::new_static("userDid"),
                                SmolStr::new_static("critical"),
                                SmolStr::new_static("high"), SmolStr::new_static("medium"),
                                SmolStr::new_static("low"), SmolStr::new_static("total"),
                                SmolStr::new_static("scannerVersion"),
                                SmolStr::new_static("scannedAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("critical"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("high"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("low"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("manifest"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT-URI of the scanned manifest (e.g., at://did:plc:xyz/io.atcr.manifest/abc123...)",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("medium"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("repository"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Repository name (e.g., myapp)"),
                                    ),
                                    max_length: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sbomBlob"),
                                LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                            );
                            map.insert(
                                SmolStr::new_static("scannedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "RFC3339 timestamp of when the scan completed",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("scannerVersion"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Version of the scanner that produced this result (e.g., atcr-scanner-v1.0.0)",
                                        ),
                                    ),
                                    max_length: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("total"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("userDid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("DID of the image owner"),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("vulnReportBlob"),
                                LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}