// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.deckbelcher.deck.list
//
// 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, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::com_deckbelcher::CardRef;
use crate::com_deckbelcher::richtext::Document;
use crate::com_deckbelcher::deck::list;
/// A card entry in a decklist.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Card<'a> {
    ///Number of copies in the deck.
    pub quantity: i64,
    ///Reference to the card (scryfall printing + oracle card).
    #[serde(borrow)]
    pub r#ref: CardRef<'a>,
    ///Which section of the deck this card belongs to. Extensible to support format-specific sections.
    #[serde(borrow)]
    pub section: list::Section<'a>,
    ///User annotations for this card in this deck (e.g., "removal", "wincon", "ramp").
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tags: Option<Vec<CowStr<'a>>>,
}

/// Game format for a deck.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Format<'a> {
    Standard,
    Pioneer,
    Modern,
    Legacy,
    Vintage,
    Pauper,
    Commander,
    Duel,
    Paupercommander,
    Predh,
    Oathbreaker,
    Brawl,
    Standardbrawl,
    Historic,
    Timeless,
    Alchemy,
    Gladiator,
    Premodern,
    Oldschool,
    Draft,
    Penny,
    Cube,
    Kitchentable,
    Other(CowStr<'a>),
}

impl<'a> Format<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Standard => "standard",
            Self::Pioneer => "pioneer",
            Self::Modern => "modern",
            Self::Legacy => "legacy",
            Self::Vintage => "vintage",
            Self::Pauper => "pauper",
            Self::Commander => "commander",
            Self::Duel => "duel",
            Self::Paupercommander => "paupercommander",
            Self::Predh => "predh",
            Self::Oathbreaker => "oathbreaker",
            Self::Brawl => "brawl",
            Self::Standardbrawl => "standardbrawl",
            Self::Historic => "historic",
            Self::Timeless => "timeless",
            Self::Alchemy => "alchemy",
            Self::Gladiator => "gladiator",
            Self::Premodern => "premodern",
            Self::Oldschool => "oldschool",
            Self::Draft => "draft",
            Self::Penny => "penny",
            Self::Cube => "cube",
            Self::Kitchentable => "kitchentable",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for Format<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "standard" => Self::Standard,
            "pioneer" => Self::Pioneer,
            "modern" => Self::Modern,
            "legacy" => Self::Legacy,
            "vintage" => Self::Vintage,
            "pauper" => Self::Pauper,
            "commander" => Self::Commander,
            "duel" => Self::Duel,
            "paupercommander" => Self::Paupercommander,
            "predh" => Self::Predh,
            "oathbreaker" => Self::Oathbreaker,
            "brawl" => Self::Brawl,
            "standardbrawl" => Self::Standardbrawl,
            "historic" => Self::Historic,
            "timeless" => Self::Timeless,
            "alchemy" => Self::Alchemy,
            "gladiator" => Self::Gladiator,
            "premodern" => Self::Premodern,
            "oldschool" => Self::Oldschool,
            "draft" => Self::Draft,
            "penny" => Self::Penny,
            "cube" => Self::Cube,
            "kitchentable" => Self::Kitchentable,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for Format<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "standard" => Self::Standard,
            "pioneer" => Self::Pioneer,
            "modern" => Self::Modern,
            "legacy" => Self::Legacy,
            "vintage" => Self::Vintage,
            "pauper" => Self::Pauper,
            "commander" => Self::Commander,
            "duel" => Self::Duel,
            "paupercommander" => Self::Paupercommander,
            "predh" => Self::Predh,
            "oathbreaker" => Self::Oathbreaker,
            "brawl" => Self::Brawl,
            "standardbrawl" => Self::Standardbrawl,
            "historic" => Self::Historic,
            "timeless" => Self::Timeless,
            "alchemy" => Self::Alchemy,
            "gladiator" => Self::Gladiator,
            "premodern" => Self::Premodern,
            "oldschool" => Self::Oldschool,
            "draft" => Self::Draft,
            "penny" => Self::Penny,
            "cube" => Self::Cube,
            "kitchentable" => Self::Kitchentable,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

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

impl jacquard_common::IntoStatic for Format<'_> {
    type Output = Format<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            Format::Standard => Format::Standard,
            Format::Pioneer => Format::Pioneer,
            Format::Modern => Format::Modern,
            Format::Legacy => Format::Legacy,
            Format::Vintage => Format::Vintage,
            Format::Pauper => Format::Pauper,
            Format::Commander => Format::Commander,
            Format::Duel => Format::Duel,
            Format::Paupercommander => Format::Paupercommander,
            Format::Predh => Format::Predh,
            Format::Oathbreaker => Format::Oathbreaker,
            Format::Brawl => Format::Brawl,
            Format::Standardbrawl => Format::Standardbrawl,
            Format::Historic => Format::Historic,
            Format::Timeless => Format::Timeless,
            Format::Alchemy => Format::Alchemy,
            Format::Gladiator => Format::Gladiator,
            Format::Premodern => Format::Premodern,
            Format::Oldschool => Format::Oldschool,
            Format::Draft => Format::Draft,
            Format::Penny => Format::Penny,
            Format::Cube => Format::Cube,
            Format::Kitchentable => Format::Kitchentable,
            Format::Other(v) => Format::Other(v.into_static()),
        }
    }
}

/// A Magic: The Gathering decklist.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct List<'a> {
    ///Array of cards in the decklist.
    #[serde(borrow)]
    pub cards: Vec<list::Card<'a>>,
    ///Timestamp when the decklist was created.
    pub created_at: Datetime,
    ///Format of the deck.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub format: Option<list::Format<'a>>,
    ///Name of the decklist.
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///Deck primer with strategy, combos, and card choices.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub primer: Option<ListPrimer<'a>>,
    ///Timestamp when the decklist was last updated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ListPrimer<'a> {
    #[serde(rename = "com.deckbelcher.richtext#document")]
    RichtextDocument(Box<Document<'a>>),
    #[serde(rename = "com.deckbelcher.deck.list#primerUri")]
    PrimerUri(Box<list::PrimerUri<'a>>),
    #[serde(rename = "com.deckbelcher.deck.list#primerRef")]
    PrimerRef(Box<list::PrimerRef<'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 ListGetRecordOutput<'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: List<'a>,
}

/// Primer in a separate ATProto record. For use with any longform writing lexicon.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PrimerRef<'a> {
    #[serde(borrow)]
    pub r#ref: StrongRef<'a>,
}

/// External primer content. Typically a URL, but any valid URI scheme.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct PrimerUri<'a> {
    #[serde(borrow)]
    pub uri: CowStr<'a>,
}

/// Which section of the deck this card belongs to. Extensible to support format-specific sections.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Section<'a> {
    Mainboard,
    Sideboard,
    Maybeboard,
    Commander,
    Other(CowStr<'a>),
}

impl<'a> Section<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Mainboard => "mainboard",
            Self::Sideboard => "sideboard",
            Self::Maybeboard => "maybeboard",
            Self::Commander => "commander",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for Section<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "mainboard" => Self::Mainboard,
            "sideboard" => Self::Sideboard,
            "maybeboard" => Self::Maybeboard,
            "commander" => Self::Commander,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for Section<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "mainboard" => Self::Mainboard,
            "sideboard" => Self::Sideboard,
            "maybeboard" => Self::Maybeboard,
            "commander" => Self::Commander,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

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

impl jacquard_common::IntoStatic for Section<'_> {
    type Output = Section<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            Section::Mainboard => Section::Mainboard,
            Section::Sideboard => Section::Sideboard,
            Section::Maybeboard => Section::Maybeboard,
            Section::Commander => Section::Commander,
            Section::Other(v) => Section::Other(v.into_static()),
        }
    }
}

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

impl<'a> LexiconSchema for Card<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.deck.list"
    }
    fn def_name() -> &'static str {
        "card"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_deck_list()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.quantity;
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("quantity"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.tags {
            #[allow(unused_comparisons)]
            if value.len() > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tags"),
                    max: 128usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct ListRecord;
impl XrpcResp for ListRecord {
    const NSID: &'static str = "com.deckbelcher.deck.list";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ListGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for List<'_> {
    const NSID: &'static str = "com.deckbelcher.deck.list";
    type Record = ListRecord;
}

impl Collection for ListRecord {
    const NSID: &'static str = "com.deckbelcher.deck.list";
    type Record = ListRecord;
}

impl<'a> LexiconSchema for List<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.deck.list"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_deck_list()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1280usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 1280usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 128usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("name"),
                        max: 128usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for PrimerRef<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.deck.list"
    }
    fn def_name() -> &'static str {
        "primerRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_deck_list()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for PrimerUri<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.deck.list"
    }
    fn def_name() -> &'static str {
        "primerUri"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_deck_list()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.uri;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("uri"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.uri;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("uri"),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod card_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 Ref;
        type Quantity;
        type Section;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Ref = Unset;
        type Quantity = Unset;
        type Section = Unset;
    }
    ///State transition - sets the `ref` field to Set
    pub struct SetRef<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRef<S> {}
    impl<S: State> State for SetRef<S> {
        type Ref = Set<members::r#ref>;
        type Quantity = S::Quantity;
        type Section = S::Section;
    }
    ///State transition - sets the `quantity` field to Set
    pub struct SetQuantity<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetQuantity<S> {}
    impl<S: State> State for SetQuantity<S> {
        type Ref = S::Ref;
        type Quantity = Set<members::quantity>;
        type Section = S::Section;
    }
    ///State transition - sets the `section` field to Set
    pub struct SetSection<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSection<S> {}
    impl<S: State> State for SetSection<S> {
        type Ref = S::Ref;
        type Quantity = S::Quantity;
        type Section = Set<members::section>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `ref` field
        pub struct r#ref(());
        ///Marker type for the `quantity` field
        pub struct quantity(());
        ///Marker type for the `section` field
        pub struct section(());
    }
}

/// Builder for constructing an instance of this type
pub struct CardBuilder<'a, S: card_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<i64>,
        Option<CardRef<'a>>,
        Option<list::Section<'a>>,
        Option<Vec<CowStr<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Card<'a> {
    /// Create a new builder for this type
    pub fn new() -> CardBuilder<'a, card_state::Empty> {
        CardBuilder::new()
    }
}

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

impl<'a, S> CardBuilder<'a, S>
where
    S: card_state::State,
    S::Quantity: card_state::IsUnset,
{
    /// Set the `quantity` field (required)
    pub fn quantity(
        mut self,
        value: impl Into<i64>,
    ) -> CardBuilder<'a, card_state::SetQuantity<S>> {
        self._fields.0 = Option::Some(value.into());
        CardBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CardBuilder<'a, S>
where
    S: card_state::State,
    S::Ref: card_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<CardRef<'a>>,
    ) -> CardBuilder<'a, card_state::SetRef<S>> {
        self._fields.1 = Option::Some(value.into());
        CardBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CardBuilder<'a, S>
where
    S: card_state::State,
    S::Section: card_state::IsUnset,
{
    /// Set the `section` field (required)
    pub fn section(
        mut self,
        value: impl Into<list::Section<'a>>,
    ) -> CardBuilder<'a, card_state::SetSection<S>> {
        self._fields.2 = Option::Some(value.into());
        CardBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> CardBuilder<'a, S>
where
    S: card_state::State,
    S::Ref: card_state::IsSet,
    S::Quantity: card_state::IsSet,
    S::Section: card_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Card<'a> {
        Card {
            quantity: self._fields.0.unwrap(),
            r#ref: self._fields.1.unwrap(),
            section: self._fields.2.unwrap(),
            tags: self._fields.3,
            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>,
        >,
    ) -> Card<'a> {
        Card {
            quantity: self._fields.0.unwrap(),
            r#ref: self._fields.1.unwrap(),
            section: self._fields.2.unwrap(),
            tags: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_deckbelcher_deck_list() -> 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("com.deckbelcher.deck.list"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("card"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A card entry in a decklist.")),
                    required: Some(
                        vec![
                            SmolStr::new_static("ref"), SmolStr::new_static("quantity"),
                            SmolStr::new_static("section")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("quantity"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.deckbelcher.defs#cardRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("section"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#section"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("tags"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "User annotations for this card in this deck (e.g., \"removal\", \"wincon\", \"ramp\").",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    description: Some(
                                        CowStr::new_static("A tag annotation for a card."),
                                    ),
                                    max_length: Some(640usize),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("format"),
                LexUserType::String(LexString {
                    description: Some(CowStr::new_static("Game format for a deck.")),
                    max_length: Some(320usize),
                    max_graphemes: Some(32usize),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("A Magic: The Gathering decklist."),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"), SmolStr::new_static("cards"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("cards"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("Array of cards in the decklist."),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#card"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp when the decklist was created.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("format"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#format"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Name of the decklist."),
                                    ),
                                    max_length: Some(1280usize),
                                    max_graphemes: Some(128usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("primer"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "Deck primer with strategy, combos, and card choices.",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("com.deckbelcher.richtext#document"),
                                        CowStr::new_static("#primerUri"),
                                        CowStr::new_static("#primerRef")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp when the decklist was last updated.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("primerRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Primer in a separate ATProto record. For use with any longform writing lexicon.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("ref")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("primerUri"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "External primer content. Typically a URL, but any valid URI scheme.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("uri")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(10000usize),
                                max_graphemes: Some(1000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("section"),
                LexUserType::String(LexString {
                    description: Some(
                        CowStr::new_static(
                            "Which section of the deck this card belongs to. Extensible to support format-specific sections.",
                        ),
                    ),
                    max_length: Some(640usize),
                    max_graphemes: Some(64usize),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type
pub struct ListBuilder<'a, S: list_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<list::Card<'a>>>,
        Option<Datetime>,
        Option<list::Format<'a>>,
        Option<CowStr<'a>>,
        Option<ListPrimer<'a>>,
        Option<Datetime>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> List<'a> {
    /// Create a new builder for this type
    pub fn new() -> ListBuilder<'a, list_state::Empty> {
        ListBuilder::new()
    }
}

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

impl<'a, S> ListBuilder<'a, S>
where
    S: list_state::State,
    S::Cards: list_state::IsUnset,
{
    /// Set the `cards` field (required)
    pub fn cards(
        mut self,
        value: impl Into<Vec<list::Card<'a>>>,
    ) -> ListBuilder<'a, list_state::SetCards<S>> {
        self._fields.0 = Option::Some(value.into());
        ListBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S: list_state::State> ListBuilder<'a, S> {
    /// Set the `format` field (optional)
    pub fn format(mut self, value: impl Into<Option<list::Format<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `format` field to an Option value (optional)
    pub fn maybe_format(mut self, value: Option<list::Format<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<'a, S: list_state::State> ListBuilder<'a, S> {
    /// Set the `primer` field (optional)
    pub fn primer(mut self, value: impl Into<Option<ListPrimer<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `primer` field to an Option value (optional)
    pub fn maybe_primer(mut self, value: Option<ListPrimer<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: list_state::State> ListBuilder<'a, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `updatedAt` field to an Option value (optional)
    pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S> ListBuilder<'a, S>
where
    S: list_state::State,
    S::Cards: list_state::IsSet,
    S::Name: list_state::IsSet,
    S::CreatedAt: list_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> List<'a> {
        List {
            cards: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            format: self._fields.2,
            name: self._fields.3.unwrap(),
            primer: self._fields.4,
            updated_at: self._fields.5,
            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>,
        >,
    ) -> List<'a> {
        List {
            cards: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            format: self._fields.2,
            name: self._fields.3.unwrap(),
            primer: self._fields.4,
            updated_at: self._fields.5,
            extra_data: Some(extra_data),
        }
    }
}

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

/// Builder for constructing an instance of this type
pub struct PrimerRefBuilder<'a, S: primer_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<StrongRef<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> PrimerRef<'a> {
    /// Create a new builder for this type
    pub fn new() -> PrimerRefBuilder<'a, primer_ref_state::Empty> {
        PrimerRefBuilder::new()
    }
}

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

impl<'a, S> PrimerRefBuilder<'a, S>
where
    S: primer_ref_state::State,
    S::Ref: primer_ref_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<StrongRef<'a>>,
    ) -> PrimerRefBuilder<'a, primer_ref_state::SetRef<S>> {
        self._fields.0 = Option::Some(value.into());
        PrimerRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PrimerRefBuilder<'a, S>
where
    S: primer_ref_state::State,
    S::Ref: primer_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> PrimerRef<'a> {
        PrimerRef {
            r#ref: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> PrimerRef<'a> {
        PrimerRef {
            r#ref: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}