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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
/// A sampling or collecting event. Multiple dwc.occurrence records can reference the same event via eventRef, sharing location and protocol metadata.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Event<'a> {
    ///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")]
    #[serde(borrow)]
    pub country: Option<CowStr<'a>>,
    ///ISO 3166-1 alpha-2 country code.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub country_code: Option<CowStr<'a>>,
    ///Second-level administrative division.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub county: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub decimal_latitude: Option<CowStr<'a>>,
    ///Geographic longitude in decimal degrees (WGS84). Range: -180 to 180.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub decimal_longitude: Option<CowStr<'a>>,
    ///The date or date range during which the event occurred. ISO 8601 format (e.g., '2024-03-15', '2024-03-15/2024-03-17').
    #[serde(borrow)]
    pub event_date: CowStr<'a>,
    ///An identifier for the event. Should be globally unique or unique within the dataset.
    #[serde(borrow)]
    pub event_id: CowStr<'a>,
    ///Comments or notes about the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub event_remarks: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub event_time: Option<CowStr<'a>>,
    ///Notes or a reference to notes taken in the field about the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub field_notes: Option<CowStr<'a>>,
    ///The spatial reference system. Recommended: 'EPSG:4326'.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub geodetic_datum: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub habitat: Option<CowStr<'a>>,
    ///Specific locality description.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub locality: Option<CowStr<'a>>,
    ///Identifier for the location where the event occurred.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub location_id: Option<CowStr<'a>>,
    ///Comments about the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub location_remarks: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub municipality: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub parent_event_id: Option<CowStr<'a>>,
    ///AT-URI reference to the parent app.gainforest.dwc.event record.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub parent_event_ref: Option<AtUri<'a>>,
    ///The unit of measurement for the sampleSizeValue (e.g., 'square meters', 'hectares', 'trap-nights').
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub sample_size_unit: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub sample_size_value: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub sampling_effort: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub sampling_protocol: Option<CowStr<'a>>,
    ///First-level administrative division.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub state_province: Option<CowStr<'a>>,
}

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EventGetRecordOutput<'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: Event<'a>,
}

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

/// 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<'de> = EventGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Event<'_> {
    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<'a> LexiconSchema for Event<'a> {
    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 EventId;
        type EventDate;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type EventId = Unset;
        type EventDate = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `event_id` field to Set
    pub struct SetEventId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEventId<S> {}
    impl<S: State> State for SetEventId<S> {
        type EventId = Set<members::event_id>;
        type EventDate = S::EventDate;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `event_date` field to Set
    pub struct SetEventDate<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEventDate<S> {}
    impl<S: State> State for SetEventDate<S> {
        type EventId = S::EventId;
        type EventDate = Set<members::event_date>;
        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 EventId = S::EventId;
        type EventDate = S::EventDate;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `event_id` field
        pub struct event_id(());
        ///Marker type for the `event_date` field
        pub struct event_date(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

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

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

impl<'a> EventBuilder<'a, event_state::Empty> {
    /// Create a new builder with all fields unset
    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,
            ),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, 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<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `country` field (optional)
    pub fn country(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `country` field to an Option value (optional)
    pub fn maybe_country(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `countryCode` field (optional)
    pub fn country_code(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `decimalLatitude` field (optional)
    pub fn decimal_latitude(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `decimalLongitude` field (optional)
    pub fn decimal_longitude(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

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

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `eventRemarks` field (optional)
    pub fn event_remarks(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.9 = value;
        self
    }
}

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

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `fieldNotes` field (optional)
    pub fn field_notes(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `geodeticDatum` field (optional)
    pub fn geodetic_datum(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.12 = value;
        self
    }
}

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

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

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `locationID` field (optional)
    pub fn location_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.15 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `locationRemarks` field (optional)
    pub fn location_remarks(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.16 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, 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<'a, S: event_state::State> EventBuilder<'a, 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<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `municipality` field (optional)
    pub fn municipality(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.19 = value.into();
        self
    }
    /// Set the `municipality` field to an Option value (optional)
    pub fn maybe_municipality(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.19 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `parentEventID` field (optional)
    pub fn parent_event_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.20 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `parentEventRef` field (optional)
    pub fn parent_event_ref(mut self, value: impl Into<Option<AtUri<'a>>>) -> 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<'a>>) -> Self {
        self._fields.21 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `sampleSizeUnit` field (optional)
    pub fn sample_size_unit(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.22 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `sampleSizeValue` field (optional)
    pub fn sample_size_value(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.23 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `samplingEffort` field (optional)
    pub fn sampling_effort(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.24 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `samplingProtocol` field (optional)
    pub fn sampling_protocol(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.25 = value;
        self
    }
}

impl<'a, S: event_state::State> EventBuilder<'a, S> {
    /// Set the `stateProvince` field (optional)
    pub fn state_province(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.26 = value;
        self
    }
}

impl<'a, S> EventBuilder<'a, S>
where
    S: event_state::State,
    S::EventId: event_state::IsSet,
    S::EventDate: event_state::IsSet,
    S::CreatedAt: event_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Event<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Event<'a> {
        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()
    }
}