// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: science.alt.dataset.lens
//
// 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::science_alt::dataset::programming_language::ProgrammingLanguage;
use crate::science_alt::dataset::lens;
/// Reference to code in an external repository (GitHub, tangled.org, etc.)

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CodeReference<S: BosStr = DefaultStr> {
    ///Optional branch name (for reference, commit hash is authoritative)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub branch: Option<S>,
    ///Git commit hash (ensures immutability)
    pub commit: S,
    ///Programming language of the code at this reference. Prefer this over the top-level language field for per-function granularity.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<ProgrammingLanguage<S>>,
    ///Path to function within repository (e.g., 'lenses/vision.py:rgb_to_grayscale')
    pub path: S,
    ///Repository URL (e.g., 'https://github.com/user/repo' or 'at://did/tangled.repo/...')
    pub repository: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Open metadata object for lens records. Applications may extend with additional fields (author, performance notes, etc.).

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LensMetadata<S: BosStr = DefaultStr> {
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Bidirectional transformation (Lens) between two sample types, with code stored in external repositories

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "science.alt.dataset.lens",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Lens<S: BosStr = DefaultStr> {
    ///Timestamp when this lens was created
    pub created_at: Datetime,
    ///What this transformation does
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///Code reference for getter function (Source -> Target)
    pub getter_code: lens::CodeReference<S>,
    ///(Deprecated: use codeReference.language instead.) Programming language of the lens implementation (e.g., 'python', 'typescript')
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<S>,
    ///Arbitrary metadata (author, performance notes, etc.)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<lens::LensMetadata<S>>,
    ///Human-readable lens name
    pub name: S,
    ///Code reference for putter function (Target, Source -> Source)
    pub putter_code: lens::CodeReference<S>,
    ///AT-URI reference to source schema
    pub source_schema: AtUri<S>,
    ///Semver version or range for source schema compatibility (e.g., '1.0.0', '>=1.0.0 <2.0.0')
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_schema_version: Option<S>,
    ///AT-URI reference to target schema
    pub target_schema: AtUri<S>,
    ///Semver version or range for target schema compatibility (e.g., '1.0.0', '>=1.0.0 <2.0.0')
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_schema_version: Option<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 LensGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Lens<S>,
}

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

impl<S: BosStr> LexiconSchema for CodeReference<S> {
    fn nsid() -> &'static str {
        "science.alt.dataset.lens"
    }
    fn def_name() -> &'static str {
        "codeReference"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_science_alt_dataset_lens()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.branch {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("branch"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.commit;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 40usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("commit"),
                    max: 40usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.path;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("path"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.repository;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("repository"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for LensMetadata<S> {
    fn nsid() -> &'static str {
        "science.alt.dataset.lens"
    }
    fn def_name() -> &'static str {
        "lensMetadata"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_science_alt_dataset_lens()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

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

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

impl<S: BosStr> LexiconSchema for Lens<S> {
    fn nsid() -> &'static str {
        "science.alt.dataset.lens"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_science_alt_dataset_lens()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.language {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("language"),
                    max: 50usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.source_schema;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("source_schema"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.source_schema_version {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("source_schema_version"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.target_schema;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("target_schema"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.target_schema_version {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("target_schema_version"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_science_alt_dataset_lens() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("science.alt.dataset.lens"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("codeReference"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Reference to code in an external repository (GitHub, tangled.org, etc.)",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("repository"),
                            SmolStr::new_static("commit"), SmolStr::new_static("path")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("branch"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional branch name (for reference, commit hash is authoritative)",
                                    ),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("commit"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Git commit hash (ensures immutability)"),
                                ),
                                max_length: Some(40usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("language"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "science.alt.dataset.programmingLanguage",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("path"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Path to function within repository (e.g., 'lenses/vision.py:rgb_to_grayscale')",
                                    ),
                                ),
                                max_length: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("repository"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Repository URL (e.g., 'https://github.com/user/repo' or 'at://did/tangled.repo/...')",
                                    ),
                                ),
                                max_length: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("lensMetadata"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Open metadata object for lens records. Applications may extend with additional fields (author, performance notes, etc.).",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Bidirectional transformation (Lens) between two sample types, with code stored in external repositories",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"),
                                SmolStr::new_static("sourceSchema"),
                                SmolStr::new_static("targetSchema"),
                                SmolStr::new_static("getterCode"),
                                SmolStr::new_static("putterCode"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Timestamp when this lens was created"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("What this transformation does"),
                                    ),
                                    max_length: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("getterCode"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#codeReference"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("language"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "(Deprecated: use codeReference.language instead.) Programming language of the lens implementation (e.g., 'python', 'typescript')",
                                        ),
                                    ),
                                    max_length: Some(50usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("metadata"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#lensMetadata"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Human-readable lens name"),
                                    ),
                                    max_length: Some(100usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("putterCode"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#codeReference"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sourceSchema"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("AT-URI reference to source schema"),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    max_length: Some(500usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sourceSchemaVersion"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Semver version or range for source schema compatibility (e.g., '1.0.0', '>=1.0.0 <2.0.0')",
                                        ),
                                    ),
                                    max_length: Some(100usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("targetSchema"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("AT-URI reference to target schema"),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    max_length: Some(500usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("targetSchemaVersion"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Semver version or range for target schema compatibility (e.g., '1.0.0', '>=1.0.0 <2.0.0')",
                                        ),
                                    ),
                                    max_length: Some(100usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod lens_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 GetterCode;
        type Name;
        type PutterCode;
        type SourceSchema;
        type TargetSchema;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type GetterCode = Unset;
        type Name = Unset;
        type PutterCode = Unset;
        type SourceSchema = Unset;
        type TargetSchema = 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 GetterCode = St::GetterCode;
        type Name = St::Name;
        type PutterCode = St::PutterCode;
        type SourceSchema = St::SourceSchema;
        type TargetSchema = St::TargetSchema;
    }
    ///State transition - sets the `getter_code` field to Set
    pub struct SetGetterCode<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetGetterCode<St> {}
    impl<St: State> State for SetGetterCode<St> {
        type CreatedAt = St::CreatedAt;
        type GetterCode = Set<members::getter_code>;
        type Name = St::Name;
        type PutterCode = St::PutterCode;
        type SourceSchema = St::SourceSchema;
        type TargetSchema = St::TargetSchema;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type CreatedAt = St::CreatedAt;
        type GetterCode = St::GetterCode;
        type Name = Set<members::name>;
        type PutterCode = St::PutterCode;
        type SourceSchema = St::SourceSchema;
        type TargetSchema = St::TargetSchema;
    }
    ///State transition - sets the `putter_code` field to Set
    pub struct SetPutterCode<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPutterCode<St> {}
    impl<St: State> State for SetPutterCode<St> {
        type CreatedAt = St::CreatedAt;
        type GetterCode = St::GetterCode;
        type Name = St::Name;
        type PutterCode = Set<members::putter_code>;
        type SourceSchema = St::SourceSchema;
        type TargetSchema = St::TargetSchema;
    }
    ///State transition - sets the `source_schema` field to Set
    pub struct SetSourceSchema<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSourceSchema<St> {}
    impl<St: State> State for SetSourceSchema<St> {
        type CreatedAt = St::CreatedAt;
        type GetterCode = St::GetterCode;
        type Name = St::Name;
        type PutterCode = St::PutterCode;
        type SourceSchema = Set<members::source_schema>;
        type TargetSchema = St::TargetSchema;
    }
    ///State transition - sets the `target_schema` field to Set
    pub struct SetTargetSchema<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTargetSchema<St> {}
    impl<St: State> State for SetTargetSchema<St> {
        type CreatedAt = St::CreatedAt;
        type GetterCode = St::GetterCode;
        type Name = St::Name;
        type PutterCode = St::PutterCode;
        type SourceSchema = St::SourceSchema;
        type TargetSchema = Set<members::target_schema>;
    }
    /// 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 `getter_code` field
        pub struct getter_code(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `putter_code` field
        pub struct putter_code(());
        ///Marker type for the `source_schema` field
        pub struct source_schema(());
        ///Marker type for the `target_schema` field
        pub struct target_schema(());
    }
}

/// Builder for constructing an instance of this type.
pub struct LensBuilder<St: lens_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Datetime>,
        Option<S>,
        Option<lens::CodeReference<S>>,
        Option<S>,
        Option<lens::LensMetadata<S>>,
        Option<S>,
        Option<lens::CodeReference<S>>,
        Option<AtUri<S>>,
        Option<S>,
        Option<AtUri<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Lens<S> {
    /// Create a new builder for this type
    pub fn builder() -> LensBuilder<lens_state::Empty, S> {
        LensBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> LensBuilder<St, S>
where
    St: lens_state::State,
    St::GetterCode: lens_state::IsUnset,
{
    /// Set the `getterCode` field (required)
    pub fn getter_code(
        mut self,
        value: impl Into<lens::CodeReference<S>>,
    ) -> LensBuilder<lens_state::SetGetterCode<St>, S> {
        self._fields.2 = Option::Some(value.into());
        LensBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

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

impl<St, S: BosStr> LensBuilder<St, S>
where
    St: lens_state::State,
    St::PutterCode: lens_state::IsUnset,
{
    /// Set the `putterCode` field (required)
    pub fn putter_code(
        mut self,
        value: impl Into<lens::CodeReference<S>>,
    ) -> LensBuilder<lens_state::SetPutterCode<St>, S> {
        self._fields.6 = Option::Some(value.into());
        LensBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LensBuilder<St, S>
where
    St: lens_state::State,
    St::SourceSchema: lens_state::IsUnset,
{
    /// Set the `sourceSchema` field (required)
    pub fn source_schema(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> LensBuilder<lens_state::SetSourceSchema<St>, S> {
        self._fields.7 = Option::Some(value.into());
        LensBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: lens_state::State, S: BosStr> LensBuilder<St, S> {
    /// Set the `sourceSchemaVersion` field (optional)
    pub fn source_schema_version(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `sourceSchemaVersion` field to an Option value (optional)
    pub fn maybe_source_schema_version(mut self, value: Option<S>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St, S: BosStr> LensBuilder<St, S>
where
    St: lens_state::State,
    St::TargetSchema: lens_state::IsUnset,
{
    /// Set the `targetSchema` field (required)
    pub fn target_schema(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> LensBuilder<lens_state::SetTargetSchema<St>, S> {
        self._fields.9 = Option::Some(value.into());
        LensBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: lens_state::State, S: BosStr> LensBuilder<St, S> {
    /// Set the `targetSchemaVersion` field (optional)
    pub fn target_schema_version(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `targetSchemaVersion` field to an Option value (optional)
    pub fn maybe_target_schema_version(mut self, value: Option<S>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St, S: BosStr> LensBuilder<St, S>
where
    St: lens_state::State,
    St::CreatedAt: lens_state::IsSet,
    St::GetterCode: lens_state::IsSet,
    St::Name: lens_state::IsSet,
    St::PutterCode: lens_state::IsSet,
    St::SourceSchema: lens_state::IsSet,
    St::TargetSchema: lens_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Lens<S> {
        Lens {
            created_at: self._fields.0.unwrap(),
            description: self._fields.1,
            getter_code: self._fields.2.unwrap(),
            language: self._fields.3,
            metadata: self._fields.4,
            name: self._fields.5.unwrap(),
            putter_code: self._fields.6.unwrap(),
            source_schema: self._fields.7.unwrap(),
            source_schema_version: self._fields.8,
            target_schema: self._fields.9.unwrap(),
            target_schema_version: self._fields.10,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Lens<S> {
        Lens {
            created_at: self._fields.0.unwrap(),
            description: self._fields.1,
            getter_code: self._fields.2.unwrap(),
            language: self._fields.3,
            metadata: self._fields.4,
            name: self._fields.5.unwrap(),
            putter_code: self._fields.6.unwrap(),
            source_schema: self._fields.7.unwrap(),
            source_schema_version: self._fields.8,
            target_schema: self._fields.9.unwrap(),
            target_schema_version: self._fields.10,
            extra_data: Some(extra_data),
        }
    }
}