// @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, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, 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.

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

/// Game format for a deck.

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

impl<S: BosStr> Format<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "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(s),
        }
    }
}

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

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for Format<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = Format<S::Output>;
    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.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "com.deckbelcher.deck.list",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct List<S: BosStr = DefaultStr> {
    ///Array of cards in the decklist.
    pub cards: Vec<list::Card<S>>,
    ///Timestamp when the decklist was created.
    pub created_at: Datetime,
    ///Format of the deck.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub format: Option<list::Format<S>>,
    ///Name of the decklist.
    pub name: S,
    ///Deck primer with strategy, combos, and card choices.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub primer: Option<ListPrimer<S>>,
    ///Timestamp when the decklist was last updated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum ListPrimer<S: BosStr = DefaultStr> {
    #[serde(rename = "com.deckbelcher.richtext#document")]
    RichtextDocument(Box<Document<S>>),
    #[serde(rename = "com.deckbelcher.deck.list#primerUri")]
    PrimerUri(Box<list::PrimerUri<S>>),
    #[serde(rename = "com.deckbelcher.deck.list#primerRef")]
    PrimerRef(Box<list::PrimerRef<S>>),
}

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

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

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PrimerRef<S: BosStr = DefaultStr> {
    pub r#ref: StrongRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PrimerUri<S: BosStr = DefaultStr> {
    pub uri: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Section<S: BosStr = DefaultStr> {
    Mainboard,
    Sideboard,
    Maybeboard,
    Commander,
    Other(S),
}

impl<S: BosStr> Section<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "mainboard" => Self::Mainboard,
            "sideboard" => Self::Sideboard,
            "maybeboard" => Self::Maybeboard,
            "commander" => Self::Commander,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for Section<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = Section<S::Output>;
    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<S: BosStr> List<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, ListRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

impl<S: BosStr> LexiconSchema for Card<S> {
    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<S: BosStr> = ListGetRecordOutput<S>;
    type Err = RecordError;
}

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

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

/// Builder for constructing an instance of this type.
pub struct CardBuilder<St: card_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<i64>, Option<CardRef<S>>, Option<list::Section<S>>, Option<Vec<S>>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

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

impl<St: card_state::State, S: BosStr> CardBuilder<St, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> 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<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> CardBuilder<St, S>
where
    St: card_state::State,
    St::Quantity: card_state::IsSet,
    St::Ref: card_state::IsSet,
    St::Section: card_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Card<S> {
        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<SmolStr, Data<S>>) -> Card<S> {
        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 CreatedAt;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cards = Unset;
        type CreatedAt = Unset;
        type Name = Unset;
    }
    ///State transition - sets the `cards` field to Set
    pub struct SetCards<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCards<St> {}
    impl<St: State> State for SetCards<St> {
        type Cards = Set<members::cards>;
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type Cards = St::Cards;
        type CreatedAt = Set<members::created_at>;
        type Name = St::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Cards = St::Cards;
        type CreatedAt = St::CreatedAt;
        type Name = Set<members::name>;
    }
    /// 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 `created_at` field
        pub struct created_at(());
        ///Marker type for the `name` field
        pub struct name(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ListBuilder<St: list_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<list::Card<S>>>,
        Option<Datetime>,
        Option<list::Format<S>>,
        Option<S>,
        Option<ListPrimer<S>>,
        Option<Datetime>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

impl<St: list_state::State, S: BosStr> ListBuilder<St, S> {
    /// Set the `format` field (optional)
    pub fn format(mut self, value: impl Into<Option<list::Format<S>>>) -> 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<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<St: list_state::State, S: BosStr> ListBuilder<St, S> {
    /// Set the `primer` field (optional)
    pub fn primer(mut self, value: impl Into<Option<ListPrimer<S>>>) -> 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<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: list_state::State, S: BosStr> ListBuilder<St, 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<St, S: BosStr> ListBuilder<St, S>
where
    St: list_state::State,
    St::Cards: list_state::IsSet,
    St::CreatedAt: list_state::IsSet,
    St::Name: list_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> List<S> {
        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<SmolStr, Data<S>>) -> List<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRef<St> {}
    impl<St: State> State for SetRef<St> {
        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<St: primer_ref_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<StrongRef<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> PrimerRefBuilder<St, S>
where
    St: primer_ref_state::State,
    St::Ref: primer_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> PrimerRef<S> {
        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<SmolStr, Data<S>>,
    ) -> PrimerRef<S> {
        PrimerRef {
            r#ref: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}