import { DayRepository, FoodLogRepository } from '@/add-log/repository'; import { getDatabase } from '@/remote/database'; import type { FoodLog, FoodRecommendation } from '@/types/foodlog'; import type { Nutrition } from '@/types/nutrition'; import * as Crypto from 'expo-crypto'; const INGREDIENT_NUTRITION: Record> = { 'salmon fillet': { protein_g: 22, fat_g: 12, omega_3_mg: 2000, vitamin_d_mcg: 11, b12_mcg: 3, usa_gov_dga_protein_g: 22, }, salmon: { protein_g: 20, fat_g: 13, omega_3_mg: 2000, vitamin_d_mcg: 11, b12_mcg: 3, usa_gov_dga_protein_g: 20, }, 'beef sirloin': { protein_g: 26, fat_g: 8, iron_mg: 2.8, b12_mcg: 2.6, zinc_mg: 5, usa_gov_dga_protein_g: 26, }, 'ground beef': { protein_g: 20, fat_g: 17, iron_mg: 2.5, b12_mcg: 2.5, zinc_mg: 5, usa_gov_dga_protein_g: 20, }, 'silken tofu': { protein_g: 5, fat_g: 2.5, calcium_mg: 150, usa_gov_dga_protein_g: 5 }, 'canned anchovies': { protein_g: 29, fat_g: 10, omega_3_mg: 2000, sodium_mg: 1200, calcium_mg: 230, usa_gov_dga_protein_g: 29, }, 'salted duck egg': { protein_g: 9, fat_g: 14, sodium_mg: 800, usa_gov_dga_protein_g: 9 }, 'preserved duck egg': { protein_g: 9, fat_g: 10, iron_mg: 2.5, usa_gov_dga_protein_g: 9 }, 'brown rice': { carbs_g: 23, protein_g: 2.6, fiber_g: 1.8, magnesium_mg: 44, usa_gov_dga_whole_grains_oz_eq: 1, }, 'mixed rice': { carbs_g: 25, protein_g: 2.5, fiber_g: 1.2, magnesium_mg: 30 }, rice: { carbs_g: 28, protein_g: 2.7, fiber_g: 0.4 }, 'instant ramen': { carbs_g: 52, protein_g: 10, fat_g: 14, sodium_mg: 1800 }, 'iceberg lettuce': { carbs_g: 3, fiber_g: 1.2, a_mcg: 25, k_mcg: 24, usa_gov_dga_vegetables_cup_eq: 0.3, usa_gov_dga_other_veg_cup_eq: 0.3, }, lettuce: { carbs_g: 2, fiber_g: 1.3, a_mcg: 370, k_mcg: 126, usa_gov_dga_vegetables_cup_eq: 0.3, usa_gov_dga_dark_green_veg_cup_eq: 0.3, }, kale: { carbs_g: 9, fiber_g: 3.6, a_mcg: 500, k_mcg: 817, c_mg: 120, usa_gov_dga_vegetables_cup_eq: 0.5, usa_gov_dga_dark_green_veg_cup_eq: 0.5, }, radish: { carbs_g: 4, fiber_g: 1.6, c_mg: 15, usa_gov_dga_vegetables_cup_eq: 0.3, usa_gov_dga_other_veg_cup_eq: 0.3, }, onion: { carbs_g: 9, fiber_g: 1.7, c_mg: 7.4, usa_gov_dga_vegetables_cup_eq: 0.2, usa_gov_dga_other_veg_cup_eq: 0.2, }, 'cherry tomatoes': { carbs_g: 4, fiber_g: 1.2, c_mg: 14, potassium_mg: 237, lycopene_mcg: 2573, usa_gov_dga_vegetables_cup_eq: 0.5, usa_gov_dga_red_orange_veg_cup_eq: 0.5, }, kimchi: { fiber_g: 2, c_mg: 18, probiotics_cfu: 1000000000, sodium_mg: 670, usa_gov_dga_vegetables_cup_eq: 0.3, usa_gov_dga_other_veg_cup_eq: 0.3, }, banana: { carbs_g: 23, fiber_g: 2.6, potassium_mg: 358, b6_mg: 0.4, c_mg: 9, usa_gov_dga_fruits_cup_eq: 0.5, }, tangerine: { carbs_g: 13, fiber_g: 1.8, c_mg: 27, usa_gov_dga_fruits_cup_eq: 0.5 }, figs: { carbs_g: 19, fiber_g: 3, potassium_mg: 232, calcium_mg: 35, usa_gov_dga_fruits_cup_eq: 0.5, }, 'mala hua jiao you': { fat_g: 100 }, coffee: { caffeine_mg: 95, magnesium_mg: 7 }, 'vitamin c': { c_mg: 1000 }, 'vitamin d': { vitamin_d_mcg: 50 }, 'fish oil': { omega_3_mg: 1000, epa_mg: 400, dha_mg: 300 }, 'lutein and zeaxanthin': { lutein_zeaxanthin_mcg: 10000 }, 'quercetin and bromelain': {}, 'homocysteine nutrients': { b6_mg: 10, b9_mcg: 400, b12_mcg: 500 }, 'vitamin b12': { b12_mcg: 1000 }, }; export function computeNutrition(ingredients: string[]): Nutrition { const result: Nutrition = {}; for (const ingredient of ingredients) { const key = ingredient.toLowerCase(); const data = INGREDIENT_NUTRITION[key]; if (data) { for (const [k, v] of Object.entries(data)) { const nutrientKey = k as keyof Nutrition; result[nutrientKey] = (result[nutrientKey] ?? 0) + (v ?? 0); } } } return result; } export const DEMO_FOODLOGS: Pick[] = [ { foodName: 'Salmon Bowl', ingredients: ['salmon fillet', 'brown rice', 'iceberg lettuce', 'banana'], eatenAt: '2026-01-18T12:00:00.000Z', date: '2026-01-18', }, { foodName: 'Salmon Salad Rice', ingredients: ['iceberg lettuce', 'mixed rice', 'salmon', 'tangerine'], eatenAt: '2026-01-17T12:00:00.000Z', date: '2026-01-17', }, { foodName: 'Daily Supplements', ingredients: [ 'vitamin c', 'vitamin d', 'fish oil', 'lutein and zeaxanthin', 'quercetin and bromelain', 'homocysteine nutrients', 'vitamin b12', ], eatenAt: '2026-01-16T08:00:00.000Z', date: '2026-01-16', }, { foodName: 'Morning Coffee', ingredients: ['coffee'], eatenAt: '2026-01-16T09:00:00.000Z', date: '2026-01-16', }, { foodName: 'Fruit and Rice', ingredients: ['cherry tomatoes', 'banana', 'mixed rice'], eatenAt: '2026-01-16T12:00:00.000Z', date: '2026-01-16', }, { foodName: 'Beef Stir Fry', ingredients: ['beef sirloin', 'radish', 'onion'], eatenAt: '2026-01-16T19:00:00.000Z', date: '2026-01-16', }, { foodName: 'Korean Breakfast', ingredients: ['salted duck egg', 'kimchi', 'mixed rice', 'beef sirloin', 'radish', 'onion'], eatenAt: '2026-01-15T08:00:00.000Z', date: '2026-01-15', }, { foodName: 'Beef Dinner', ingredients: ['beef sirloin', 'radish', 'onion'], eatenAt: '2026-01-15T19:00:00.000Z', date: '2026-01-15', }, { foodName: 'Korean Beef Bowl', ingredients: ['beef sirloin', 'preserved duck egg', 'onion', 'radish', 'rice', 'figs'], eatenAt: '2026-01-14T12:00:00.000Z', date: '2026-01-14', }, { foodName: 'Mala Tofu Salad', ingredients: ['mala hua jiao you', 'lettuce', 'kale', 'silken tofu', 'ground beef'], eatenAt: '2026-01-13T12:00:00.000Z', date: '2026-01-13', }, { foodName: 'Quick Lunch', ingredients: ['banana', 'canned anchovies', 'instant ramen', 'coffee'], eatenAt: '2026-01-13T15:00:00.000Z', date: '2026-01-13', }, ]; type DayRecommendations = { date: string; ingredients: string[]; foods: FoodRecommendation[] }; export const DEMO_RECOMMENDATIONS: DayRecommendations[] = [ { date: '2026-01-18', ingredients: [ 'Spinach', 'Greek Yogurt', 'Almonds', 'Chickpeas', 'Sweet Potato', 'Broccoli', 'Lentils', 'Avocado', 'Edamame', 'Chia Seeds', 'Sardines', 'Bell Pepper', 'Quinoa', 'Eggs', 'Kale', ], foods: [ { recommendedFoodName: 'Spinach Egg Scramble', ingredients: ['spinach', 'eggs', 'feta', 'olive oil'], }, { recommendedFoodName: 'Greek Yogurt Parfait', ingredients: ['greek yogurt', 'berries', 'almonds', 'honey'], }, { recommendedFoodName: 'Chickpea Curry', ingredients: ['chickpeas', 'spinach', 'coconut milk', 'tomatoes'], }, ], }, ]; export async function seedDemoData(): Promise { const db = getDatabase(); const foodLogRepo = new FoodLogRepository(db); const dayRepo = new DayRepository(db); const existingLogs = await foodLogRepo.getAll(); if (existingLogs.length > 0) return; for (const log of DEMO_FOODLOGS) { const eatenAt = new Date(log.eatenAt); const nutrition = computeNutrition(log.ingredients); const dayId = await dayRepo.getOrCreateDay('demo', eatenAt); await foodLogRepo.create({ id: Crypto.randomUUID(), profileId: 'demo', dayId, foodName: log.foodName, ingredients: log.ingredients, nutrition, eatenAt, status: 'completed', }); } for (const rec of DEMO_RECOMMENDATIONS) { await dayRepo.updateRecommendations('demo', rec.date, rec.ingredients, rec.foods); } }