// @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;

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct CodeReference<'a> {
    ///Optional branch name (for reference, commit hash is authoritative)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub branch: Option<CowStr<'a>>,
    ///Git commit hash (ensures immutability)
    #[serde(borrow)]
    pub commit: CowStr<'a>,
    ///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")]
    #[serde(borrow)]
    pub language: Option<ProgrammingLanguage<'a>>,
    ///Path to function within repository (e.g., 'lenses/vision.py:rgb_to_grayscale')
    #[serde(borrow)]
    pub path: CowStr<'a>,
    ///Repository URL (e.g., 'https://github.com/user/repo' or 'at://did/tangled.repo/...')
    #[serde(borrow)]
    pub repository: CowStr<'a>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct LensMetadata<'a> {}
/// Bidirectional transformation (Lens) between two sample types, with code stored in external repositories

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Lens<'a> {
    ///Timestamp when this lens was created
    pub created_at: Datetime,
    ///What this transformation does
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    ///Code reference for getter function (Source -> Target)
    #[serde(borrow)]
    pub getter_code: lens::CodeReference<'a>,
    ///(Deprecated: use codeReference.language instead.) Programming language of the lens implementation (e.g., 'python', 'typescript')
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub language: Option<CowStr<'a>>,
    ///Arbitrary metadata (author, performance notes, etc.)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub metadata: Option<lens::LensMetadata<'a>>,
    ///Human-readable lens name
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///Code reference for putter function (Target, Source -> Source)
    #[serde(borrow)]
    pub putter_code: lens::CodeReference<'a>,
    ///AT-URI reference to source schema
    #[serde(borrow)]
    pub source_schema: AtUri<'a>,
    ///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")]
    #[serde(borrow)]
    pub source_schema_version: Option<CowStr<'a>>,
    ///AT-URI reference to target schema
    #[serde(borrow)]
    pub target_schema: AtUri<'a>,
    ///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")]
    #[serde(borrow)]
    pub target_schema_version: Option<CowStr<'a>>,
}

/// 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<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Lens<'a>,
}

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

impl<'a> LexiconSchema for CodeReference<'a> {
    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<'a> LexiconSchema for LensMetadata<'a> {
    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<'de> = LensGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Lens<'_> {
    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<'a> LexiconSchema for Lens<'a> {
    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 Name;
        type GetterCode;
        type TargetSchema;
        type SourceSchema;
        type PutterCode;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Name = Unset;
        type GetterCode = Unset;
        type TargetSchema = Unset;
        type SourceSchema = Unset;
        type PutterCode = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Name = Set<members::name>;
        type GetterCode = S::GetterCode;
        type TargetSchema = S::TargetSchema;
        type SourceSchema = S::SourceSchema;
        type PutterCode = S::PutterCode;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `getter_code` field to Set
    pub struct SetGetterCode<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetGetterCode<S> {}
    impl<S: State> State for SetGetterCode<S> {
        type Name = S::Name;
        type GetterCode = Set<members::getter_code>;
        type TargetSchema = S::TargetSchema;
        type SourceSchema = S::SourceSchema;
        type PutterCode = S::PutterCode;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `target_schema` field to Set
    pub struct SetTargetSchema<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTargetSchema<S> {}
    impl<S: State> State for SetTargetSchema<S> {
        type Name = S::Name;
        type GetterCode = S::GetterCode;
        type TargetSchema = Set<members::target_schema>;
        type SourceSchema = S::SourceSchema;
        type PutterCode = S::PutterCode;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `source_schema` field to Set
    pub struct SetSourceSchema<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSourceSchema<S> {}
    impl<S: State> State for SetSourceSchema<S> {
        type Name = S::Name;
        type GetterCode = S::GetterCode;
        type TargetSchema = S::TargetSchema;
        type SourceSchema = Set<members::source_schema>;
        type PutterCode = S::PutterCode;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `putter_code` field to Set
    pub struct SetPutterCode<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPutterCode<S> {}
    impl<S: State> State for SetPutterCode<S> {
        type Name = S::Name;
        type GetterCode = S::GetterCode;
        type TargetSchema = S::TargetSchema;
        type SourceSchema = S::SourceSchema;
        type PutterCode = Set<members::putter_code>;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Name = S::Name;
        type GetterCode = S::GetterCode;
        type TargetSchema = S::TargetSchema;
        type SourceSchema = S::SourceSchema;
        type PutterCode = S::PutterCode;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `getter_code` field
        pub struct getter_code(());
        ///Marker type for the `target_schema` field
        pub struct target_schema(());
        ///Marker type for the `source_schema` field
        pub struct source_schema(());
        ///Marker type for the `putter_code` field
        pub struct putter_code(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct LensBuilder<'a, S: lens_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<lens::CodeReference<'a>>,
        Option<CowStr<'a>>,
        Option<lens::LensMetadata<'a>>,
        Option<CowStr<'a>>,
        Option<lens::CodeReference<'a>>,
        Option<AtUri<'a>>,
        Option<CowStr<'a>>,
        Option<AtUri<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

impl<'a, S: lens_state::State> LensBuilder<'a, S> {
    /// Set the `metadata` field (optional)
    pub fn metadata(mut self, value: impl Into<Option<lens::LensMetadata<'a>>>) -> 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<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

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

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

impl<'a, S: lens_state::State> LensBuilder<'a, S> {
    /// Set the `sourceSchemaVersion` field (optional)
    pub fn source_schema_version(
        mut self,
        value: impl Into<Option<CowStr<'a>>>,
    ) -> 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<CowStr<'a>>) -> Self {
        self._fields.8 = value;
        self
    }
}

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

impl<'a, S: lens_state::State> LensBuilder<'a, S> {
    /// Set the `targetSchemaVersion` field (optional)
    pub fn target_schema_version(
        mut self,
        value: impl Into<Option<CowStr<'a>>>,
    ) -> 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<CowStr<'a>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<'a, S> LensBuilder<'a, S>
where
    S: lens_state::State,
    S::Name: lens_state::IsSet,
    S::GetterCode: lens_state::IsSet,
    S::TargetSchema: lens_state::IsSet,
    S::SourceSchema: lens_state::IsSet,
    S::PutterCode: lens_state::IsSet,
    S::CreatedAt: lens_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Lens<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Lens<'a> {
        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),
        }
    }
}