// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: net.altq.aqfile
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::ident::AtIdentifier;
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::net_altq::aqfile;
/// Cryptographic checksum for integrity verification.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Checksum<'a> {
    ///Hash algorithm name.
    #[serde(borrow)]
    pub algo: ChecksumAlgo<'a>,
    ///Hex or base64 encoded digest produced by the algorithm.
    #[serde(borrow)]
    pub hash: CowStr<'a>,
}

/// Hash algorithm name.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ChecksumAlgo<'a> {
    Sha256,
    Sha512,
    Blake3,
    Other(CowStr<'a>),
}

impl<'a> ChecksumAlgo<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Sha256 => "sha256",
            Self::Sha512 => "sha512",
            Self::Blake3 => "blake3",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for ChecksumAlgo<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "sha256" => Self::Sha256,
            "sha512" => Self::Sha512,
            "blake3" => Self::Blake3,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ChecksumAlgo<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "sha256" => Self::Sha256,
            "sha512" => Self::Sha512,
            "blake3" => Self::Blake3,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

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

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

impl jacquard_common::IntoStatic for ChecksumAlgo<'_> {
    type Output = ChecksumAlgo<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            ChecksumAlgo::Sha256 => ChecksumAlgo::Sha256,
            ChecksumAlgo::Sha512 => ChecksumAlgo::Sha512,
            ChecksumAlgo::Blake3 => ChecksumAlgo::Blake3,
            ChecksumAlgo::Other(v) => ChecksumAlgo::Other(v.into_static()),
        }
    }
}

/// File metadata describing the uploaded blob.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct File<'a> {
    ///MIME type, e.g. 'video/mp4'.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub mime_type: Option<CowStr<'a>>,
    ///Client-side last-modified timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modified_at: Option<Datetime>,
    ///User-visible filename.
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///File size in bytes.
    pub size: i64,
}

/// A record representing an uploaded file blob with metadata.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Aqfile<'a> {
    ///Handle or DID of the account to attribute this upload to.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub attribution: Option<AtIdentifier<'a>>,
    ///The uploaded blob reference. Note: Individual PDS instances may enforce lower size limits.
    #[serde(borrow)]
    pub blob: BlobRef<'a>,
    ///Optional cryptographic checksum for integrity verification.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub checksum: Option<aqfile::Checksum<'a>>,
    ///Timestamp when this record was created.
    pub created_at: Datetime,
    ///Metadata about the file.
    #[serde(borrow)]
    pub file: aqfile::File<'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 AqfileGetRecordOutput<'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: Aqfile<'a>,
}

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

impl<'a> LexiconSchema for Checksum<'a> {
    fn nsid() -> &'static str {
        "net.altq.aqfile"
    }
    fn def_name() -> &'static str {
        "checksum"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_altq_aqfile()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.algo;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("algo"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.hash;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("hash"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for File<'a> {
    fn nsid() -> &'static str {
        "net.altq.aqfile"
    }
    fn def_name() -> &'static str {
        "file"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_altq_aqfile()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.mime_type {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 255usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("mime_type"),
                    max: 255usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 512usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 512usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.size;
            if *value > 1000000000i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("size"),
                    max: 1000000000i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.size;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("size"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct AqfileRecord;
impl XrpcResp for AqfileRecord {
    const NSID: &'static str = "net.altq.aqfile";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = AqfileGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Aqfile<'_> {
    const NSID: &'static str = "net.altq.aqfile";
    type Record = AqfileRecord;
}

impl Collection for AqfileRecord {
    const NSID: &'static str = "net.altq.aqfile";
    type Record = AqfileRecord;
}

impl<'a> LexiconSchema for Aqfile<'a> {
    fn nsid() -> &'static str {
        "net.altq.aqfile"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_altq_aqfile()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.blob;
            {
                let size = value.blob().size;
                if size > 1000000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("blob"),
                        max: 1000000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.blob;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["*/*"];
                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("blob"),
                        accepted: vec!["*/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

fn lexicon_doc_net_altq_aqfile() -> 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("net.altq.aqfile"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("checksum"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Cryptographic checksum for integrity verification.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("algo"), SmolStr::new_static("hash")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("algo"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Hash algorithm name."),
                                ),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("hash"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Hex or base64 encoded digest produced by the algorithm.",
                                    ),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("file"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("File metadata describing the uploaded blob."),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("name"), SmolStr::new_static("size")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("mimeType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("MIME type, e.g. 'video/mp4'."),
                                ),
                                max_length: Some(255usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("modifiedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Client-side last-modified timestamp."),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("User-visible filename."),
                                ),
                                max_length: Some(512usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("size"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(1000000000i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A record representing an uploaded file blob with metadata.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("blob"),
                                SmolStr::new_static("createdAt"),
                                SmolStr::new_static("file")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("attribution"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Handle or DID of the account to attribute this upload to.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtIdentifier),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("blob"),
                                LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                            );
                            map.insert(
                                SmolStr::new_static("checksum"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#checksum"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp when this record was created.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("file"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#file"),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

impl<'a> File<'a> {
    /// Create a new builder for this type
    pub fn new() -> FileBuilder<'a, file_state::Empty> {
        FileBuilder::new()
    }
}

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

impl<'a, S: file_state::State> FileBuilder<'a, S> {
    /// Set the `mimeType` field (optional)
    pub fn mime_type(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `mimeType` field to an Option value (optional)
    pub fn maybe_mime_type(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: file_state::State> FileBuilder<'a, S> {
    /// Set the `modifiedAt` field (optional)
    pub fn modified_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `modifiedAt` field to an Option value (optional)
    pub fn maybe_modified_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<'a, S> FileBuilder<'a, S>
where
    S: file_state::State,
    S::Size: file_state::IsSet,
    S::Name: file_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> File<'a> {
        File {
            mime_type: self._fields.0,
            modified_at: self._fields.1,
            name: self._fields.2.unwrap(),
            size: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> File<'a> {
        File {
            mime_type: self._fields.0,
            modified_at: self._fields.1,
            name: self._fields.2.unwrap(),
            size: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod aqfile_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 File;
        type Blob;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type File = Unset;
        type Blob = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `file` field to Set
    pub struct SetFile<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetFile<S> {}
    impl<S: State> State for SetFile<S> {
        type File = Set<members::file>;
        type Blob = S::Blob;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `blob` field to Set
    pub struct SetBlob<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBlob<S> {}
    impl<S: State> State for SetBlob<S> {
        type File = S::File;
        type Blob = Set<members::blob>;
        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 File = S::File;
        type Blob = S::Blob;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `file` field
        pub struct file(());
        ///Marker type for the `blob` field
        pub struct blob(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct AqfileBuilder<'a, S: aqfile_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<AtIdentifier<'a>>,
        Option<BlobRef<'a>>,
        Option<aqfile::Checksum<'a>>,
        Option<Datetime>,
        Option<aqfile::File<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Aqfile<'a> {
    /// Create a new builder for this type
    pub fn new() -> AqfileBuilder<'a, aqfile_state::Empty> {
        AqfileBuilder::new()
    }
}

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

impl<'a, S: aqfile_state::State> AqfileBuilder<'a, S> {
    /// Set the `attribution` field (optional)
    pub fn attribution(mut self, value: impl Into<Option<AtIdentifier<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `attribution` field to an Option value (optional)
    pub fn maybe_attribution(mut self, value: Option<AtIdentifier<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> AqfileBuilder<'a, S>
where
    S: aqfile_state::State,
    S::Blob: aqfile_state::IsUnset,
{
    /// Set the `blob` field (required)
    pub fn blob(
        mut self,
        value: impl Into<BlobRef<'a>>,
    ) -> AqfileBuilder<'a, aqfile_state::SetBlob<S>> {
        self._fields.1 = Option::Some(value.into());
        AqfileBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: aqfile_state::State> AqfileBuilder<'a, S> {
    /// Set the `checksum` field (optional)
    pub fn checksum(mut self, value: impl Into<Option<aqfile::Checksum<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `checksum` field to an Option value (optional)
    pub fn maybe_checksum(mut self, value: Option<aqfile::Checksum<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<'a, S> AqfileBuilder<'a, S>
where
    S: aqfile_state::State,
    S::File: aqfile_state::IsUnset,
{
    /// Set the `file` field (required)
    pub fn file(
        mut self,
        value: impl Into<aqfile::File<'a>>,
    ) -> AqfileBuilder<'a, aqfile_state::SetFile<S>> {
        self._fields.4 = Option::Some(value.into());
        AqfileBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> AqfileBuilder<'a, S>
where
    S: aqfile_state::State,
    S::File: aqfile_state::IsSet,
    S::Blob: aqfile_state::IsSet,
    S::CreatedAt: aqfile_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Aqfile<'a> {
        Aqfile {
            attribution: self._fields.0,
            blob: self._fields.1.unwrap(),
            checksum: self._fields.2,
            created_at: self._fields.3.unwrap(),
            file: self._fields.4.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Aqfile<'a> {
        Aqfile {
            attribution: self._fields.0,
            blob: self._fields.1.unwrap(),
            checksum: self._fields.2,
            created_at: self._fields.3.unwrap(),
            file: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}