1use std::collections::HashMap;
2
3use chrono::NaiveDate;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct ScaleEntry {
9 pub date: NaiveDate,
10 pub weight: f64,
12 pub body_fat: Option<f64>,
14 pub source: Option<String>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct NutritionSummary {
21 pub date: NaiveDate,
22 pub calories: Option<f64>,
24 pub protein: Option<f64>,
26 pub carbs: Option<f64>,
28 pub fat: Option<f64>,
30 pub sugar: Option<f64>,
32 pub fiber: Option<f64>,
34 pub source: Option<String>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct FoodServing {
41 pub description: String,
43 pub amount: f64,
45 pub gram_weight: f64,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct SearchFoodResult {
52 pub food_id: String,
54 pub name: String,
56 pub brand: Option<String>,
58 pub calories_per_100g: f64,
60 pub protein_per_100g: f64,
62 pub fat_per_100g: f64,
64 pub carbs_per_100g: f64,
66 pub default_serving: Option<FoodServing>,
68 pub servings: Vec<FoodServing>,
70 pub image_id: Option<String>,
72 pub nutrients_per_100g: HashMap<String, f64>,
74 pub source: Option<String>,
76 pub branded: bool,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct FoodEntry {
87 pub date: NaiveDate,
88 pub entry_id: String,
90 pub name: Option<String>,
92 pub brand: Option<String>,
94 pub calories_raw: Option<f64>,
96 pub protein_raw: Option<f64>,
98 pub carbs_raw: Option<f64>,
100 pub fat_raw: Option<f64>,
102 pub serving_grams: Option<f64>,
104 pub user_qty: Option<f64>,
106 pub unit_weight: Option<f64>,
108 pub quantity: Option<f64>,
110 pub serving_unit: Option<String>,
112 pub hour: Option<String>,
114 pub minute: Option<String>,
116 pub source_type: Option<String>,
118 pub food_id: Option<String>,
120 pub deleted: Option<bool>,
122}
123
124impl FoodEntry {
125 pub fn multiplier(&self) -> Option<f64> {
127 match (self.serving_grams, self.user_qty, self.unit_weight) {
128 (Some(g), Some(y), Some(w)) if g > 0.0 => Some((y * w) / g),
129 _ => None,
130 }
131 }
132
133 pub fn calories(&self) -> Option<f64> {
135 match (self.calories_raw, self.multiplier()) {
136 (Some(v), Some(m)) => Some(v * m),
137 _ => self.calories_raw,
138 }
139 }
140
141 pub fn protein(&self) -> Option<f64> {
143 match (self.protein_raw, self.multiplier()) {
144 (Some(v), Some(m)) => Some(v * m),
145 _ => self.protein_raw,
146 }
147 }
148
149 pub fn carbs(&self) -> Option<f64> {
151 match (self.carbs_raw, self.multiplier()) {
152 (Some(v), Some(m)) => Some(v * m),
153 _ => self.carbs_raw,
154 }
155 }
156
157 pub fn fat(&self) -> Option<f64> {
159 match (self.fat_raw, self.multiplier()) {
160 (Some(v), Some(m)) => Some(v * m),
161 _ => self.fat_raw,
162 }
163 }
164
165 pub fn weight_grams(&self) -> Option<f64> {
167 match (self.user_qty, self.unit_weight) {
168 (Some(y), Some(w)) => Some(y * w),
169 _ => None,
170 }
171 }
172}
173
174#[derive(Debug, Clone, Serialize, Deserialize)]
176pub struct StepEntry {
177 pub date: NaiveDate,
178 pub steps: u64,
180 pub source: Option<String>,
182}
183
184#[derive(Debug, Clone, Serialize, Deserialize)]
186pub struct Goals {
187 pub calories: Vec<f64>,
189 pub protein: Vec<f64>,
191 pub carbs: Vec<f64>,
193 pub fat: Vec<f64>,
195 pub tdee: Option<f64>,
197 pub program_style: Option<String>,
199 pub program_type: Option<String>,
201}
202
203#[derive(Debug, Clone, Serialize, Deserialize)]
205pub struct UserProfile {
206 pub id: String,
207 pub name: Option<String>,
208 pub email: Option<String>,
209 pub sex: Option<String>,
210 pub dob: Option<String>,
211 pub height: Option<f64>,
212 pub height_units: Option<String>,
213 pub weight_units: Option<String>,
214 pub calorie_units: Option<String>,
215}