// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: io.kich.recipe.recipe
//
// 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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::io_kich::recipe::recipe;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Ingredient<S: BosStr = DefaultStr> {
    ///[Deprecated] Amount needed in grams. Use measuredAmount/measuredUnit instead.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub grams: Option<i64>,
    ///Optional group name for organizing ingredients (e.g., 'For the sauce:', 'For the pasta:')
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group: Option<S>,
    ///Heuristic amount from parsed ingredient text (e.g., 2 in "2 cups")
    #[serde(skip_serializing_if = "Option::is_none")]
    pub heuristic_amount: Option<i64>,
    ///Heuristic unit from parsed ingredient text (e.g., cup, cookies)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub heuristic_unit: Option<S>,
    ///Unique identifier for this ingredient
    pub id: S,
    ///Whether this ingredient is detached (doesn't count towards recipe completeness)  Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_ingredient_is_detached")]
    pub is_detached: Option<bool>,
    ///Whether this ingredient is optional  Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_ingredient_is_optional")]
    pub is_optional: Option<bool>,
    ///Measured amount needed (e.g., 250, 1.5)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub measured_amount: Option<i64>,
    ///Measured unit (g, kg, oz, lb, ml)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub measured_unit: Option<S>,
    ///Ingredient name
    pub name: S,
    ///Optional notes about this ingredient (e.g., original quantity)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub notes: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct InstructionStep<S: BosStr = DefaultStr> {
    ///Unique identifier for this instruction step
    pub id: S,
    ///Instruction text
    pub value: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "io.kich.recipe.recipe",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Recipe<S: BosStr = DefaultStr> {
    ///Cooking time in minutes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cook_time_minutes: Option<i64>,
    ///When this recipe was created
    pub created_at: Datetime,
    ///Reference to the user who created this recipe
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_by: Option<StrongRef<S>>,
    ///Recipe description
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///Vector embedding for semantic similarity search (1024 dimensions, stored as JSON array of numbers)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub embedding: Option<S>,
    ///[Deprecated] Image URL for the recipe. Use images blob array instead. Kept for legacy fallback.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_url: Option<UriValue<S>>,
    ///Recipe images as blobs (hero first; preferred over imageUrl)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub images: Option<Vec<BlobRef<S>>>,
    ///Recipe ingredients
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ingredients: Option<Vec<recipe::Ingredient<S>>>,
    ///Cooking instructions as an array of steps
    #[serde(skip_serializing_if = "Option::is_none")]
    pub instructions: Option<Vec<recipe::InstructionStep<S>>>,
    ///Whether this recipe is private (only visible to household members)  Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_recipe_is_private")]
    pub is_private: Option<bool>,
    ///Recipe name
    pub name: S,
    ///Preparation time in minutes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prep_time_minutes: Option<i64>,
    ///Number of servings this recipe makes  Defaults to `1`.
    #[serde(default = "_default_recipe_servings")]
    pub servings: i64,
    ///Source name (book, magazine, blog)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<S>,
    ///Tags for categorizing the recipe
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<recipe::Tag<S>>>,
    ///When this recipe was last updated
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    ///Source URL of the recipe
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<UriValue<S>>,
    ///Optional reference to the original recipe this is a variation of (for attribution and variation discovery)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub variation_of: Option<StrongRef<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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


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

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

impl<S: BosStr> LexiconSchema for Ingredient<S> {
    fn nsid() -> &'static str {
        "io.kich.recipe.recipe"
    }
    fn def_name() -> &'static str {
        "ingredient"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_kich_recipe_recipe()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for InstructionStep<S> {
    fn nsid() -> &'static str {
        "io.kich.recipe.recipe"
    }
    fn def_name() -> &'static str {
        "instructionStep"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_kich_recipe_recipe()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct RecipeRecord;
impl XrpcResp for RecipeRecord {
    const NSID: &'static str = "io.kich.recipe.recipe";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = RecipeGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Recipe<S> {
    const NSID: &'static str = "io.kich.recipe.recipe";
    type Record = RecipeRecord;
}

impl Collection for RecipeRecord {
    const NSID: &'static str = "io.kich.recipe.recipe";
    type Record = RecipeRecord;
}

impl<S: BosStr> LexiconSchema for Recipe<S> {
    fn nsid() -> &'static str {
        "io.kich.recipe.recipe"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_kich_recipe_recipe()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.images {
            #[allow(unused_comparisons)]
            if value.len() > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("images"),
                    max: 10usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Tag<S> {
    fn nsid() -> &'static str {
        "io.kich.recipe.recipe"
    }
    fn def_name() -> &'static str {
        "tag"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_io_kich_recipe_recipe()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_ingredient_is_detached() -> Option<bool> {
    Some(false)
}

fn _default_ingredient_is_optional() -> Option<bool> {
    Some(false)
}

fn lexicon_doc_io_kich_recipe_recipe() -> 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("io.kich.recipe.recipe"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("ingredient"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("id"), SmolStr::new_static("name")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("grams"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("group"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional group name for organizing ingredients (e.g., 'For the sauce:', 'For the pasta:')",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("heuristicAmount"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("heuristicUnit"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Heuristic unit from parsed ingredient text (e.g., cup, cookies)",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Unique identifier for this ingredient"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isDetached"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isOptional"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("measuredAmount"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("measuredUnit"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Measured unit (g, kg, oz, lb, ml)"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Ingredient name")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("notes"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional notes about this ingredient (e.g., original quantity)",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("instructionStep"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("id"), SmolStr::new_static("value")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Unique identifier for this instruction step",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Instruction text")),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"),
                                SmolStr::new_static("servings"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("cookTimeMinutes"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When this recipe was created"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdBy"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("Recipe description")),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("embedding"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Vector embedding for semantic similarity search (1024 dimensions, stored as JSON array of numbers)",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("imageUrl"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "[Deprecated] Image URL for the recipe. Use images blob array instead. Kept for legacy fallback.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("images"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Recipe images as blobs (hero first; preferred over imageUrl)",
                                        ),
                                    ),
                                    items: LexArrayItem::Blob(LexBlob { ..Default::default() }),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("ingredients"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(CowStr::new_static("Recipe ingredients")),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#ingredient"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("instructions"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Cooking instructions as an array of steps",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#instructionStep"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("isPrivate"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("Recipe name")),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("prepTimeMinutes"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("servings"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("source"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Source name (book, magazine, blog)"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tags"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("Tags for categorizing the recipe"),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#tag"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When this recipe was last updated"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("url"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Source URL of the recipe"),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("variationOf"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("tag"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("id"), SmolStr::new_static("name")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Tag identifier")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Tag display name")),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_recipe_is_private() -> Option<bool> {
    Some(false)
}

fn _default_recipe_servings() -> i64 {
    1i64
}

pub mod recipe_state {

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

/// Builder for constructing an instance of this type.
pub struct RecipeBuilder<St: recipe_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<i64>,
        Option<Datetime>,
        Option<StrongRef<S>>,
        Option<S>,
        Option<S>,
        Option<UriValue<S>>,
        Option<Vec<BlobRef<S>>>,
        Option<Vec<recipe::Ingredient<S>>>,
        Option<Vec<recipe::InstructionStep<S>>>,
        Option<bool>,
        Option<S>,
        Option<i64>,
        Option<i64>,
        Option<S>,
        Option<Vec<recipe::Tag<S>>>,
        Option<Datetime>,
        Option<UriValue<S>>,
        Option<StrongRef<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Recipe<S> {
    /// Create a new builder for this type
    pub fn builder() -> RecipeBuilder<recipe_state::Empty, S> {
        RecipeBuilder::builder()
    }
}

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

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

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `cookTimeMinutes` field (optional)
    pub fn cook_time_minutes(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `cookTimeMinutes` field to an Option value (optional)
    pub fn maybe_cook_time_minutes(mut self, value: Option<i64>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `createdBy` field (optional)
    pub fn created_by(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `createdBy` field to an Option value (optional)
    pub fn maybe_created_by(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `embedding` field (optional)
    pub fn embedding(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `embedding` field to an Option value (optional)
    pub fn maybe_embedding(mut self, value: Option<S>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `imageUrl` field (optional)
    pub fn image_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `imageUrl` field to an Option value (optional)
    pub fn maybe_image_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `images` field (optional)
    pub fn images(mut self, value: impl Into<Option<Vec<BlobRef<S>>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `images` field to an Option value (optional)
    pub fn maybe_images(mut self, value: Option<Vec<BlobRef<S>>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `ingredients` field (optional)
    pub fn ingredients(
        mut self,
        value: impl Into<Option<Vec<recipe::Ingredient<S>>>>,
    ) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `ingredients` field to an Option value (optional)
    pub fn maybe_ingredients(
        mut self,
        value: Option<Vec<recipe::Ingredient<S>>>,
    ) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `instructions` field (optional)
    pub fn instructions(
        mut self,
        value: impl Into<Option<Vec<recipe::InstructionStep<S>>>>,
    ) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `instructions` field to an Option value (optional)
    pub fn maybe_instructions(
        mut self,
        value: Option<Vec<recipe::InstructionStep<S>>>,
    ) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `isPrivate` field (optional)
    pub fn is_private(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `isPrivate` field to an Option value (optional)
    pub fn maybe_is_private(mut self, value: Option<bool>) -> Self {
        self._fields.9 = value;
        self
    }
}

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

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `prepTimeMinutes` field (optional)
    pub fn prep_time_minutes(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `prepTimeMinutes` field to an Option value (optional)
    pub fn maybe_prep_time_minutes(mut self, value: Option<i64>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<St, S: BosStr> RecipeBuilder<St, S>
where
    St: recipe_state::State,
    St::Servings: recipe_state::IsUnset,
{
    /// Set the `servings` field (required)
    pub fn servings(
        mut self,
        value: impl Into<i64>,
    ) -> RecipeBuilder<recipe_state::SetServings<St>, S> {
        self._fields.12 = Option::Some(value.into());
        RecipeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<recipe::Tag<S>>>>) -> Self {
        self._fields.14 = value.into();
        self
    }
    /// Set the `tags` field to an Option value (optional)
    pub fn maybe_tags(mut self, value: Option<Vec<recipe::Tag<S>>>) -> Self {
        self._fields.14 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.15 = 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.15 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `url` field (optional)
    pub fn url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.16 = value.into();
        self
    }
    /// Set the `url` field to an Option value (optional)
    pub fn maybe_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.16 = value;
        self
    }
}

impl<St: recipe_state::State, S: BosStr> RecipeBuilder<St, S> {
    /// Set the `variationOf` field (optional)
    pub fn variation_of(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.17 = value.into();
        self
    }
    /// Set the `variationOf` field to an Option value (optional)
    pub fn maybe_variation_of(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.17 = value;
        self
    }
}

impl<St, S: BosStr> RecipeBuilder<St, S>
where
    St: recipe_state::State,
    St::CreatedAt: recipe_state::IsSet,
    St::Name: recipe_state::IsSet,
    St::Servings: recipe_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Recipe<S> {
        Recipe {
            cook_time_minutes: self._fields.0,
            created_at: self._fields.1.unwrap(),
            created_by: self._fields.2,
            description: self._fields.3,
            embedding: self._fields.4,
            image_url: self._fields.5,
            images: self._fields.6,
            ingredients: self._fields.7,
            instructions: self._fields.8,
            is_private: self._fields.9.or_else(|| Some(false)),
            name: self._fields.10.unwrap(),
            prep_time_minutes: self._fields.11,
            servings: self._fields.12.unwrap(),
            source: self._fields.13,
            tags: self._fields.14,
            updated_at: self._fields.15,
            url: self._fields.16,
            variation_of: self._fields.17,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Recipe<S> {
        Recipe {
            cook_time_minutes: self._fields.0,
            created_at: self._fields.1.unwrap(),
            created_by: self._fields.2,
            description: self._fields.3,
            embedding: self._fields.4,
            image_url: self._fields.5,
            images: self._fields.6,
            ingredients: self._fields.7,
            instructions: self._fields.8,
            is_private: self._fields.9.or_else(|| Some(false)),
            name: self._fields.10.unwrap(),
            prep_time_minutes: self._fields.11,
            servings: self._fields.12.unwrap(),
            source: self._fields.13,
            tags: self._fields.14,
            updated_at: self._fields.15,
            url: self._fields.16,
            variation_of: self._fields.17,
            extra_data: Some(extra_data),
        }
    }
}