1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct ScaleEntry {
7 pub date: NaiveDate,
8 pub weight: f64,
10 pub body_fat: Option<f64>,
12 pub source: Option<String>,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct NutritionSummary {
19 pub date: NaiveDate,
20 pub calories: Option<f64>,
22 pub protein: Option<f64>,
24 pub carbs: Option<f64>,
26 pub fat: Option<f64>,
28 pub sugar: Option<f64>,
30 pub fiber: Option<f64>,
32 pub source: Option<String>,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct FoodEntry {
43 pub date: NaiveDate,
44 pub entry_id: String,
46 pub name: Option<String>,
48 pub brand: Option<String>,
50 pub calories_raw: Option<f64>,
52 pub protein_raw: Option<f64>,
54 pub carbs_raw: Option<f64>,
56 pub fat_raw: Option<f64>,
58 pub serving_grams: Option<f64>,
60 pub user_qty: Option<f64>,
62 pub unit_weight: Option<f64>,
64 pub quantity: Option<f64>,
66 pub serving_unit: Option<String>,
68 pub hour: Option<String>,
70 pub minute: Option<String>,
72 pub source_type: Option<String>,
74 pub food_id: Option<String>,
76}
77
78impl FoodEntry {
79 pub fn multiplier(&self) -> Option<f64> {
81 match (self.serving_grams, self.user_qty, self.unit_weight) {
82 (Some(g), Some(y), Some(w)) if g > 0.0 => Some((y * w) / g),
83 _ => None,
84 }
85 }
86
87 pub fn calories(&self) -> Option<f64> {
89 match (self.calories_raw, self.multiplier()) {
90 (Some(v), Some(m)) => Some(v * m),
91 _ => self.calories_raw,
92 }
93 }
94
95 pub fn protein(&self) -> Option<f64> {
97 match (self.protein_raw, self.multiplier()) {
98 (Some(v), Some(m)) => Some(v * m),
99 _ => self.protein_raw,
100 }
101 }
102
103 pub fn carbs(&self) -> Option<f64> {
105 match (self.carbs_raw, self.multiplier()) {
106 (Some(v), Some(m)) => Some(v * m),
107 _ => self.carbs_raw,
108 }
109 }
110
111 pub fn fat(&self) -> Option<f64> {
113 match (self.fat_raw, self.multiplier()) {
114 (Some(v), Some(m)) => Some(v * m),
115 _ => self.fat_raw,
116 }
117 }
118
119 pub fn weight_grams(&self) -> Option<f64> {
121 match (self.user_qty, self.unit_weight) {
122 (Some(y), Some(w)) => Some(y * w),
123 _ => None,
124 }
125 }
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct StepEntry {
131 pub date: NaiveDate,
132 pub steps: u64,
134 pub source: Option<String>,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct Goals {
141 pub calories: Vec<f64>,
143 pub protein: Vec<f64>,
145 pub carbs: Vec<f64>,
147 pub fat: Vec<f64>,
149 pub tdee: Option<f64>,
151 pub program_style: Option<String>,
153 pub program_type: Option<String>,
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct UserProfile {
160 pub id: String,
161 pub name: Option<String>,
162 pub email: Option<String>,
163 pub sex: Option<String>,
164 pub dob: Option<String>,
165 pub height: Option<f64>,
166 pub height_units: Option<String>,
167 pub weight_units: Option<String>,
168 pub calorie_units: Option<String>,
169}