Skip to main content

fond_domain/
recipe.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4/// A parsed recipe — the domain-level representation of a `.cook` file.
5///
6/// Fields map to Cooklang metadata plus parsed content.  
7/// `raw_source` preserves the original `.cook` text so that
8/// user-authored files are never silently rewritten.
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
10pub struct Recipe {
11    pub slug: String,
12    pub title: String,
13    pub source: Option<String>,
14    pub source_url: Option<String>,
15    pub description: Option<String>,
16    pub recipe_yield: Option<String>,
17    pub prep_time: Option<String>,
18    pub cook_time: Option<String>,
19    pub total_time: Option<String>,
20    pub servings: Option<String>,
21    pub ingredients: Vec<RecipeIngredient>,
22    pub steps: Vec<Step>,
23    pub cookware: Vec<Cookware>,
24    pub tags: Vec<String>,
25    pub created_at: DateTime<Utc>,
26    pub updated_at: DateTime<Utc>,
27    /// Original `.cook` file content — preserved for lossless write-back.
28    pub raw_source: Option<String>,
29}
30
31/// An ingredient reference within a recipe.
32#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
33pub struct RecipeIngredient {
34    pub name: String,
35    pub quantity: Option<String>,
36    pub unit: Option<String>,
37    pub note: Option<String>,
38    pub optional: bool,
39}
40
41/// A single step (instruction) within a recipe.
42#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
43pub struct Step {
44    pub section: Option<String>,
45    pub body: String,
46    pub timers: Vec<Timer>,
47    pub order: u32,
48}
49
50/// A timer reference extracted from a step.
51#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
52pub struct Timer {
53    pub name: Option<String>,
54    pub duration: Option<String>,
55}
56
57/// A cookware reference extracted from a recipe.
58#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
59pub struct Cookware {
60    pub name: String,
61    pub quantity: Option<String>,
62}