// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.gainforest.dwc.event
//
// 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};
/// A sampling or collecting event. Multiple dwc.occurrence records can reference the same event via eventRef, sharing location and protocol metadata.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "app.gainforest.dwc.event",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Event<S: BosStr = DefaultStr> {
    ///Uncertainty radius in meters around the coordinates.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub coordinate_uncertainty_in_meters: Option<i64>,
    ///The name of the country.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<S>,
    ///ISO 3166-1 alpha-2 country code.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country_code: Option<S>,
    ///Second-level administrative division.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub county: Option<S>,
    ///Timestamp of record creation in the ATProto PDS.
    pub created_at: Datetime,
    ///Geographic latitude in decimal degrees (WGS84). Range: -90 to 90.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub decimal_latitude: Option<S>,
    ///Geographic longitude in decimal degrees (WGS84). Range: -180 to 180.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub decimal_longitude: Option<S>,
    ///The date or date range during which the event occurred. ISO 8601 format (e.g., '2024-03-15', '2024-03-15/2024-03-17').
    pub event_date: S,
    ///An identifier for the event. Should be globally unique or unique within the dataset.
    pub event_id: S,
    ///Comments or notes about the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_remarks: Option<S>,
    ///The time or time range during which the event occurred. ISO 8601 format (e.g., '06:30:00', '06:30:00/09:00:00').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_time: Option<S>,
    ///Notes or a reference to notes taken in the field about the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub field_notes: Option<S>,
    ///The spatial reference system. Recommended: 'EPSG:4326'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub geodetic_datum: Option<S>,
    ///A category or description of the habitat in which the event occurred (e.g., 'primary tropical rainforest', 'degraded pasture', 'riparian zone').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub habitat: Option<S>,
    ///Specific locality description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub locality: Option<S>,
    ///Identifier for the location where the event occurred.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location_id: Option<S>,
    ///Comments about the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location_remarks: Option<S>,
    ///Upper limit of elevation range in meters above sea level.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub maximum_elevation_in_meters: Option<i64>,
    ///Lower limit of elevation range in meters above sea level.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub minimum_elevation_in_meters: Option<i64>,
    ///Third-level administrative division.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub municipality: Option<S>,
    ///An identifier for the broader event that this event is part of (e.g., a survey campaign that contains multiple transects).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent_event_id: Option<S>,
    ///AT-URI reference to the parent app.gainforest.dwc.event record.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent_event_ref: Option<AtUri<S>>,
    ///The unit of measurement for the sampleSizeValue (e.g., 'square meters', 'hectares', 'trap-nights').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sample_size_unit: Option<S>,
    ///A numeric value for a measurement of the size of a sample in the event (e.g., '20', '0.25').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sample_size_value: Option<S>,
    ///The amount of effort expended during the event (e.g., '3 person-hours', '14 trap-nights', '2 km transect walked').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sampling_effort: Option<S>,
    ///The names of, references to, or descriptions of the methods used during the event (e.g., 'camera trap array', 'line transect distance sampling', 'audio point count 10-min').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sampling_protocol: Option<S>,
    ///First-level administrative division.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state_province: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct EventRecord;
impl XrpcResp for EventRecord {
    const NSID: &'static str = "app.gainforest.dwc.event";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = EventGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Event<S> {
    const NSID: &'static str = "app.gainforest.dwc.event";
    type Record = EventRecord;
}

impl Collection for EventRecord {
    const NSID: &'static str = "app.gainforest.dwc.event";
    type Record = EventRecord;
}

impl<S: BosStr> LexiconSchema for Event<S> {
    fn nsid() -> &'static str {
        "app.gainforest.dwc.event"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_gainforest_dwc_event()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.coordinate_uncertainty_in_meters {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("coordinate_uncertainty_in_meters"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.country {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 128usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("country"),
                        max: 128usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.country_code {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("country_code"),
                    max: 2usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.country_code {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 2usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("country_code"),
                    min: 2usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.county {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("county"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.decimal_latitude {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 32usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("decimal_latitude"),
                        max: 32usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.decimal_longitude {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 32usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("decimal_longitude"),
                        max: 32usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.event_date;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("event_date"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.event_id;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("event_id"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.event_remarks {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 5000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("event_remarks"),
                        max: 5000usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.event_time {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("event_time"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.field_notes {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 10000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("field_notes"),
                        max: 10000usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.geodetic_datum {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("geodetic_datum"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.habitat {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 512usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("habitat"),
                        max: 512usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.locality {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1024usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("locality"),
                        max: 1024usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.location_id {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("location_id"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.location_remarks {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 2048usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("location_remarks"),
                        max: 2048usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.municipality {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("municipality"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.parent_event_id {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("parent_event_id"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.sample_size_unit {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 128usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("sample_size_unit"),
                        max: 128usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.sample_size_value {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("sample_size_value"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.sampling_effort {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("sampling_effort"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.sampling_protocol {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1024usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("sampling_protocol"),
                        max: 1024usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.state_province {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("state_province"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod event_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type CreatedAt;
        type EventDate;
        type EventId;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type EventDate = Unset;
        type EventId = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type EventDate = St::EventDate;
        type EventId = St::EventId;
    }
    ///State transition - sets the `event_date` field to Set
    pub struct SetEventDate<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEventDate<St> {}
    impl<St: State> State for SetEventDate<St> {
        type CreatedAt = St::CreatedAt;
        type EventDate = Set<members::event_date>;
        type EventId = St::EventId;
    }
    ///State transition - sets the `event_id` field to Set
    pub struct SetEventId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEventId<St> {}
    impl<St: State> State for SetEventId<St> {
        type CreatedAt = St::CreatedAt;
        type EventDate = St::EventDate;
        type EventId = Set<members::event_id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `event_date` field
        pub struct event_date(());
        ///Marker type for the `event_id` field
        pub struct event_id(());
    }
}

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

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

impl<S: BosStr> Event<S> {
    /// Create a new builder for this type
    pub fn builder() -> EventBuilder<event_state::Empty, S> {
        EventBuilder::builder()
    }
}

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

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `coordinateUncertaintyInMeters` field (optional)
    pub fn coordinate_uncertainty_in_meters(
        mut self,
        value: impl Into<Option<i64>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `coordinateUncertaintyInMeters` field to an Option value (optional)
    pub fn maybe_coordinate_uncertainty_in_meters(mut self, value: Option<i64>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `countryCode` field (optional)
    pub fn country_code(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `countryCode` field to an Option value (optional)
    pub fn maybe_country_code(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `decimalLatitude` field (optional)
    pub fn decimal_latitude(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `decimalLatitude` field to an Option value (optional)
    pub fn maybe_decimal_latitude(mut self, value: Option<S>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `decimalLongitude` field (optional)
    pub fn decimal_longitude(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `decimalLongitude` field to an Option value (optional)
    pub fn maybe_decimal_longitude(mut self, value: Option<S>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::EventDate: event_state::IsUnset,
{
    /// Set the `eventDate` field (required)
    pub fn event_date(
        mut self,
        value: impl Into<S>,
    ) -> EventBuilder<event_state::SetEventDate<St>, S> {
        self._fields.7 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::EventId: event_state::IsUnset,
{
    /// Set the `eventID` field (required)
    pub fn event_id(
        mut self,
        value: impl Into<S>,
    ) -> EventBuilder<event_state::SetEventId<St>, S> {
        self._fields.8 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `eventRemarks` field (optional)
    pub fn event_remarks(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `eventRemarks` field to an Option value (optional)
    pub fn maybe_event_remarks(mut self, value: Option<S>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `eventTime` field (optional)
    pub fn event_time(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `eventTime` field to an Option value (optional)
    pub fn maybe_event_time(mut self, value: Option<S>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `fieldNotes` field (optional)
    pub fn field_notes(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `fieldNotes` field to an Option value (optional)
    pub fn maybe_field_notes(mut self, value: Option<S>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `geodeticDatum` field (optional)
    pub fn geodetic_datum(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `geodeticDatum` field to an Option value (optional)
    pub fn maybe_geodetic_datum(mut self, value: Option<S>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `habitat` field (optional)
    pub fn habitat(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.13 = value.into();
        self
    }
    /// Set the `habitat` field to an Option value (optional)
    pub fn maybe_habitat(mut self, value: Option<S>) -> Self {
        self._fields.13 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `locality` field (optional)
    pub fn locality(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.14 = value.into();
        self
    }
    /// Set the `locality` field to an Option value (optional)
    pub fn maybe_locality(mut self, value: Option<S>) -> Self {
        self._fields.14 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `locationID` field (optional)
    pub fn location_id(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.15 = value.into();
        self
    }
    /// Set the `locationID` field to an Option value (optional)
    pub fn maybe_location_id(mut self, value: Option<S>) -> Self {
        self._fields.15 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `locationRemarks` field (optional)
    pub fn location_remarks(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.16 = value.into();
        self
    }
    /// Set the `locationRemarks` field to an Option value (optional)
    pub fn maybe_location_remarks(mut self, value: Option<S>) -> Self {
        self._fields.16 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `maximumElevationInMeters` field (optional)
    pub fn maximum_elevation_in_meters(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.17 = value.into();
        self
    }
    /// Set the `maximumElevationInMeters` field to an Option value (optional)
    pub fn maybe_maximum_elevation_in_meters(mut self, value: Option<i64>) -> Self {
        self._fields.17 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `minimumElevationInMeters` field (optional)
    pub fn minimum_elevation_in_meters(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.18 = value.into();
        self
    }
    /// Set the `minimumElevationInMeters` field to an Option value (optional)
    pub fn maybe_minimum_elevation_in_meters(mut self, value: Option<i64>) -> Self {
        self._fields.18 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `municipality` field (optional)
    pub fn municipality(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.19 = value.into();
        self
    }
    /// Set the `municipality` field to an Option value (optional)
    pub fn maybe_municipality(mut self, value: Option<S>) -> Self {
        self._fields.19 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `parentEventID` field (optional)
    pub fn parent_event_id(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.20 = value.into();
        self
    }
    /// Set the `parentEventID` field to an Option value (optional)
    pub fn maybe_parent_event_id(mut self, value: Option<S>) -> Self {
        self._fields.20 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `parentEventRef` field (optional)
    pub fn parent_event_ref(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
        self._fields.21 = value.into();
        self
    }
    /// Set the `parentEventRef` field to an Option value (optional)
    pub fn maybe_parent_event_ref(mut self, value: Option<AtUri<S>>) -> Self {
        self._fields.21 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `sampleSizeUnit` field (optional)
    pub fn sample_size_unit(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.22 = value.into();
        self
    }
    /// Set the `sampleSizeUnit` field to an Option value (optional)
    pub fn maybe_sample_size_unit(mut self, value: Option<S>) -> Self {
        self._fields.22 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `sampleSizeValue` field (optional)
    pub fn sample_size_value(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.23 = value.into();
        self
    }
    /// Set the `sampleSizeValue` field to an Option value (optional)
    pub fn maybe_sample_size_value(mut self, value: Option<S>) -> Self {
        self._fields.23 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `samplingEffort` field (optional)
    pub fn sampling_effort(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.24 = value.into();
        self
    }
    /// Set the `samplingEffort` field to an Option value (optional)
    pub fn maybe_sampling_effort(mut self, value: Option<S>) -> Self {
        self._fields.24 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `samplingProtocol` field (optional)
    pub fn sampling_protocol(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.25 = value.into();
        self
    }
    /// Set the `samplingProtocol` field to an Option value (optional)
    pub fn maybe_sampling_protocol(mut self, value: Option<S>) -> Self {
        self._fields.25 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `stateProvince` field (optional)
    pub fn state_province(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.26 = value.into();
        self
    }
    /// Set the `stateProvince` field to an Option value (optional)
    pub fn maybe_state_province(mut self, value: Option<S>) -> Self {
        self._fields.26 = value;
        self
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::CreatedAt: event_state::IsSet,
    St::EventDate: event_state::IsSet,
    St::EventId: event_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Event<S> {
        Event {
            coordinate_uncertainty_in_meters: self._fields.0,
            country: self._fields.1,
            country_code: self._fields.2,
            county: self._fields.3,
            created_at: self._fields.4.unwrap(),
            decimal_latitude: self._fields.5,
            decimal_longitude: self._fields.6,
            event_date: self._fields.7.unwrap(),
            event_id: self._fields.8.unwrap(),
            event_remarks: self._fields.9,
            event_time: self._fields.10,
            field_notes: self._fields.11,
            geodetic_datum: self._fields.12,
            habitat: self._fields.13,
            locality: self._fields.14,
            location_id: self._fields.15,
            location_remarks: self._fields.16,
            maximum_elevation_in_meters: self._fields.17,
            minimum_elevation_in_meters: self._fields.18,
            municipality: self._fields.19,
            parent_event_id: self._fields.20,
            parent_event_ref: self._fields.21,
            sample_size_unit: self._fields.22,
            sample_size_value: self._fields.23,
            sampling_effort: self._fields.24,
            sampling_protocol: self._fields.25,
            state_province: self._fields.26,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Event<S> {
        Event {
            coordinate_uncertainty_in_meters: self._fields.0,
            country: self._fields.1,
            country_code: self._fields.2,
            county: self._fields.3,
            created_at: self._fields.4.unwrap(),
            decimal_latitude: self._fields.5,
            decimal_longitude: self._fields.6,
            event_date: self._fields.7.unwrap(),
            event_id: self._fields.8.unwrap(),
            event_remarks: self._fields.9,
            event_time: self._fields.10,
            field_notes: self._fields.11,
            geodetic_datum: self._fields.12,
            habitat: self._fields.13,
            locality: self._fields.14,
            location_id: self._fields.15,
            location_remarks: self._fields.16,
            maximum_elevation_in_meters: self._fields.17,
            minimum_elevation_in_meters: self._fields.18,
            municipality: self._fields.19,
            parent_event_id: self._fields.20,
            parent_event_ref: self._fields.21,
            sample_size_unit: self._fields.22,
            sample_size_value: self._fields.23,
            sampling_effort: self._fields.24,
            sampling_protocol: self._fields.25,
            state_province: self._fields.26,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_gainforest_dwc_event() -> 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("app.gainforest.dwc.event"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A sampling or collecting event. Multiple dwc.occurrence records can reference the same event via eventRef, sharing location and protocol metadata.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("eventID"),
                                SmolStr::new_static("eventDate"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("coordinateUncertaintyInMeters"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(1i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("country"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("The name of the country."),
                                    ),
                                    max_graphemes: Some(128usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("countryCode"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("ISO 3166-1 alpha-2 country code."),
                                    ),
                                    min_length: Some(2usize),
                                    max_length: Some(2usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("county"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Second-level administrative division."),
                                    ),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp of record creation in the ATProto PDS.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("decimalLatitude"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Geographic latitude in decimal degrees (WGS84). Range: -90 to 90.",
                                        ),
                                    ),
                                    max_graphemes: Some(32usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("decimalLongitude"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Geographic longitude in decimal degrees (WGS84). Range: -180 to 180.",
                                        ),
                                    ),
                                    max_graphemes: Some(32usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("eventDate"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The date or date range during which the event occurred. ISO 8601 format (e.g., '2024-03-15', '2024-03-15/2024-03-17').",
                                        ),
                                    ),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("eventID"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "An identifier for the event. Should be globally unique or unique within the dataset.",
                                        ),
                                    ),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("eventRemarks"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Comments or notes about the event."),
                                    ),
                                    max_graphemes: Some(5000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("eventTime"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The time or time range during which the event occurred. ISO 8601 format (e.g., '06:30:00', '06:30:00/09:00:00').",
                                        ),
                                    ),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("fieldNotes"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Notes or a reference to notes taken in the field about the event.",
                                        ),
                                    ),
                                    max_graphemes: Some(10000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("geodeticDatum"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The spatial reference system. Recommended: 'EPSG:4326'.",
                                        ),
                                    ),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("habitat"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "A category or description of the habitat in which the event occurred (e.g., 'primary tropical rainforest', 'degraded pasture', 'riparian zone').",
                                        ),
                                    ),
                                    max_graphemes: Some(512usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("locality"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Specific locality description."),
                                    ),
                                    max_graphemes: Some(1024usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("locationID"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Identifier for the location where the event occurred.",
                                        ),
                                    ),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("locationRemarks"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Comments about the location."),
                                    ),
                                    max_graphemes: Some(2048usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("maximumElevationInMeters"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("minimumElevationInMeters"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("municipality"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Third-level administrative division."),
                                    ),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("parentEventID"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "An identifier for the broader event that this event is part of (e.g., a survey campaign that contains multiple transects).",
                                        ),
                                    ),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("parentEventRef"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT-URI reference to the parent app.gainforest.dwc.event record.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sampleSizeUnit"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The unit of measurement for the sampleSizeValue (e.g., 'square meters', 'hectares', 'trap-nights').",
                                        ),
                                    ),
                                    max_graphemes: Some(128usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sampleSizeValue"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "A numeric value for a measurement of the size of a sample in the event (e.g., '20', '0.25').",
                                        ),
                                    ),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("samplingEffort"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The amount of effort expended during the event (e.g., '3 person-hours', '14 trap-nights', '2 km transect walked').",
                                        ),
                                    ),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("samplingProtocol"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The names of, references to, or descriptions of the methods used during the event (e.g., 'camera trap array', 'line transect distance sampling', 'audio point count 10-min').",
                                        ),
                                    ),
                                    max_graphemes: Some(1024usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("stateProvince"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("First-level administrative division."),
                                    ),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}