// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.impactindexer.link.attestation
//
// 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::org_impactindexer::link::attestation;
/// The EIP-712 typed data message structure

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Eip712Message<S: BosStr = DefaultStr> {
    ///The chain ID as a string (for bigint compatibility, max uint256)
    pub chain_id: S,
    ///The ATProto DID being linked
    pub did: S,
    ///The EVM address being linked (0x-prefixed)
    pub evm_address: S,
    ///Replay protection nonce as a string (for bigint compatibility)
    pub nonce: S,
    ///Unix timestamp as a string (for bigint compatibility)
    pub timestamp: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// An attestation linking an ATProto DID to an EVM wallet address, signed with EIP-712.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "org.impactindexer.link.attestation",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Attestation<S: BosStr = DefaultStr> {
    ///The EVM wallet address (checksummed or lowercase, 0x-prefixed)
    pub address: S,
    ///The EVM chain ID where the signature was created
    pub chain_id: i64,
    ///Timestamp when the attestation was created
    pub created_at: Datetime,
    ///The EIP-712 typed data message that was signed
    pub message: attestation::Eip712Message<S>,
    ///The EIP-712 signature in hex format (0x-prefixed, 65 bytes for ECDSA, longer for smart contract sigs)
    pub signature: S,
    ///The type of signature: eoa (EOA/ECDSA), erc1271 (smart contract), erc6492 (counterfactual)
    pub signature_type: AttestationSignatureType<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// The type of signature: eoa (EOA/ECDSA), erc1271 (smart contract), erc6492 (counterfactual)

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AttestationSignatureType<S: BosStr = DefaultStr> {
    Eoa,
    Erc1271,
    Erc6492,
    Other(S),
}

impl<S: BosStr> AttestationSignatureType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Eoa => "eoa",
            Self::Erc1271 => "erc1271",
            Self::Erc6492 => "erc6492",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "eoa" => Self::Eoa,
            "erc1271" => Self::Erc1271,
            "erc6492" => Self::Erc6492,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for AttestationSignatureType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = AttestationSignatureType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            AttestationSignatureType::Eoa => AttestationSignatureType::Eoa,
            AttestationSignatureType::Erc1271 => AttestationSignatureType::Erc1271,
            AttestationSignatureType::Erc6492 => AttestationSignatureType::Erc6492,
            AttestationSignatureType::Other(v) => {
                AttestationSignatureType::Other(v.into_static())
            }
        }
    }
}

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

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

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

impl<S: BosStr> LexiconSchema for Eip712Message<S> {
    fn nsid() -> &'static str {
        "org.impactindexer.link.attestation"
    }
    fn def_name() -> &'static str {
        "eip712Message"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_impactindexer_link_attestation()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.chain_id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 78usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("chain_id"),
                    max: 78usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.did;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2048usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("did"),
                    max: 2048usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.evm_address;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 42usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("evm_address"),
                    max: 42usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.evm_address;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 42usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("evm_address"),
                    min: 42usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.nonce;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 78usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("nonce"),
                    max: 78usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.timestamp;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 78usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("timestamp"),
                    max: 78usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct AttestationRecord;
impl XrpcResp for AttestationRecord {
    const NSID: &'static str = "org.impactindexer.link.attestation";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = AttestationGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Attestation<S> {
    const NSID: &'static str = "org.impactindexer.link.attestation";
    type Record = AttestationRecord;
}

impl Collection for AttestationRecord {
    const NSID: &'static str = "org.impactindexer.link.attestation";
    type Record = AttestationRecord;
}

impl<S: BosStr> LexiconSchema for Attestation<S> {
    fn nsid() -> &'static str {
        "org.impactindexer.link.attestation"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_impactindexer_link_attestation()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.address;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 42usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("address"),
                    max: 42usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.address;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 42usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("address"),
                    min: 42usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.chain_id;
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("chain_id"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.signature;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("signature"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.signature;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 132usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("signature"),
                    min: 132usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.signature_type;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("signature_type"),
                    max: 10usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_org_impactindexer_link_attestation() -> 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("org.impactindexer.link.attestation"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("eip712Message"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("The EIP-712 typed data message structure"),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("did"),
                            SmolStr::new_static("evmAddress"),
                            SmolStr::new_static("chainId"),
                            SmolStr::new_static("timestamp"),
                            SmolStr::new_static("nonce")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("chainId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The chain ID as a string (for bigint compatibility, max uint256)",
                                    ),
                                ),
                                max_length: Some(78usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The ATProto DID being linked"),
                                ),
                                max_length: Some(2048usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("evmAddress"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The EVM address being linked (0x-prefixed)",
                                    ),
                                ),
                                min_length: Some(42usize),
                                max_length: Some(42usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("nonce"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Replay protection nonce as a string (for bigint compatibility)",
                                    ),
                                ),
                                max_length: Some(78usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("timestamp"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Unix timestamp as a string (for bigint compatibility)",
                                    ),
                                ),
                                max_length: Some(78usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "An attestation linking an ATProto DID to an EVM wallet address, signed with EIP-712.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("address"),
                                SmolStr::new_static("chainId"),
                                SmolStr::new_static("signature"),
                                SmolStr::new_static("message"),
                                SmolStr::new_static("signatureType"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("address"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The EVM wallet address (checksummed or lowercase, 0x-prefixed)",
                                        ),
                                    ),
                                    min_length: Some(42usize),
                                    max_length: Some(42usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("chainId"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(1i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp when the attestation was created",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("message"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#eip712Message"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("signature"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The EIP-712 signature in hex format (0x-prefixed, 65 bytes for ECDSA, longer for smart contract sigs)",
                                        ),
                                    ),
                                    min_length: Some(132usize),
                                    max_length: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("signatureType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The type of signature: eoa (EOA/ECDSA), erc1271 (smart contract), erc6492 (counterfactual)",
                                        ),
                                    ),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod attestation_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 Address;
        type ChainId;
        type CreatedAt;
        type Message;
        type Signature;
        type SignatureType;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Address = Unset;
        type ChainId = Unset;
        type CreatedAt = Unset;
        type Message = Unset;
        type Signature = Unset;
        type SignatureType = Unset;
    }
    ///State transition - sets the `address` field to Set
    pub struct SetAddress<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAddress<St> {}
    impl<St: State> State for SetAddress<St> {
        type Address = Set<members::address>;
        type ChainId = St::ChainId;
        type CreatedAt = St::CreatedAt;
        type Message = St::Message;
        type Signature = St::Signature;
        type SignatureType = St::SignatureType;
    }
    ///State transition - sets the `chain_id` field to Set
    pub struct SetChainId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetChainId<St> {}
    impl<St: State> State for SetChainId<St> {
        type Address = St::Address;
        type ChainId = Set<members::chain_id>;
        type CreatedAt = St::CreatedAt;
        type Message = St::Message;
        type Signature = St::Signature;
        type SignatureType = St::SignatureType;
    }
    ///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 Address = St::Address;
        type ChainId = St::ChainId;
        type CreatedAt = Set<members::created_at>;
        type Message = St::Message;
        type Signature = St::Signature;
        type SignatureType = St::SignatureType;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMessage<St> {}
    impl<St: State> State for SetMessage<St> {
        type Address = St::Address;
        type ChainId = St::ChainId;
        type CreatedAt = St::CreatedAt;
        type Message = Set<members::message>;
        type Signature = St::Signature;
        type SignatureType = St::SignatureType;
    }
    ///State transition - sets the `signature` field to Set
    pub struct SetSignature<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSignature<St> {}
    impl<St: State> State for SetSignature<St> {
        type Address = St::Address;
        type ChainId = St::ChainId;
        type CreatedAt = St::CreatedAt;
        type Message = St::Message;
        type Signature = Set<members::signature>;
        type SignatureType = St::SignatureType;
    }
    ///State transition - sets the `signature_type` field to Set
    pub struct SetSignatureType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSignatureType<St> {}
    impl<St: State> State for SetSignatureType<St> {
        type Address = St::Address;
        type ChainId = St::ChainId;
        type CreatedAt = St::CreatedAt;
        type Message = St::Message;
        type Signature = St::Signature;
        type SignatureType = Set<members::signature_type>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `address` field
        pub struct address(());
        ///Marker type for the `chain_id` field
        pub struct chain_id(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `message` field
        pub struct message(());
        ///Marker type for the `signature` field
        pub struct signature(());
        ///Marker type for the `signature_type` field
        pub struct signature_type(());
    }
}

/// Builder for constructing an instance of this type.
pub struct AttestationBuilder<St: attestation_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<i64>,
        Option<Datetime>,
        Option<attestation::Eip712Message<S>>,
        Option<S>,
        Option<AttestationSignatureType<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Attestation<S> {
    /// Create a new builder for this type
    pub fn builder() -> AttestationBuilder<attestation_state::Empty, S> {
        AttestationBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> AttestationBuilder<St, S>
where
    St: attestation_state::State,
    St::Address: attestation_state::IsUnset,
{
    /// Set the `address` field (required)
    pub fn address(
        mut self,
        value: impl Into<S>,
    ) -> AttestationBuilder<attestation_state::SetAddress<St>, S> {
        self._fields.0 = Option::Some(value.into());
        AttestationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AttestationBuilder<St, S>
where
    St: attestation_state::State,
    St::ChainId: attestation_state::IsUnset,
{
    /// Set the `chainId` field (required)
    pub fn chain_id(
        mut self,
        value: impl Into<i64>,
    ) -> AttestationBuilder<attestation_state::SetChainId<St>, S> {
        self._fields.1 = Option::Some(value.into());
        AttestationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> AttestationBuilder<St, S>
where
    St: attestation_state::State,
    St::Message: attestation_state::IsUnset,
{
    /// Set the `message` field (required)
    pub fn message(
        mut self,
        value: impl Into<attestation::Eip712Message<S>>,
    ) -> AttestationBuilder<attestation_state::SetMessage<St>, S> {
        self._fields.3 = Option::Some(value.into());
        AttestationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AttestationBuilder<St, S>
where
    St: attestation_state::State,
    St::Signature: attestation_state::IsUnset,
{
    /// Set the `signature` field (required)
    pub fn signature(
        mut self,
        value: impl Into<S>,
    ) -> AttestationBuilder<attestation_state::SetSignature<St>, S> {
        self._fields.4 = Option::Some(value.into());
        AttestationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AttestationBuilder<St, S>
where
    St: attestation_state::State,
    St::SignatureType: attestation_state::IsUnset,
{
    /// Set the `signatureType` field (required)
    pub fn signature_type(
        mut self,
        value: impl Into<AttestationSignatureType<S>>,
    ) -> AttestationBuilder<attestation_state::SetSignatureType<St>, S> {
        self._fields.5 = Option::Some(value.into());
        AttestationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AttestationBuilder<St, S>
where
    St: attestation_state::State,
    St::Address: attestation_state::IsSet,
    St::ChainId: attestation_state::IsSet,
    St::CreatedAt: attestation_state::IsSet,
    St::Message: attestation_state::IsSet,
    St::Signature: attestation_state::IsSet,
    St::SignatureType: attestation_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Attestation<S> {
        Attestation {
            address: self._fields.0.unwrap(),
            chain_id: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            message: self._fields.3.unwrap(),
            signature: self._fields.4.unwrap(),
            signature_type: self._fields.5.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Attestation<S> {
        Attestation {
            address: self._fields.0.unwrap(),
            chain_id: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            message: self._fields.3.unwrap(),
            signature: self._fields.4.unwrap(),
            signature_type: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}