export interface User {
	id: string;
	username: string;
	display_name: string;
	telegram_user_id?: string;
}

export interface Food {
	id: string;
	name: string;
	brand?: string;
	barcode?: string;
	base_unit: string;
	calories_per_base: number;
	protein_per_base: number;
	carbs_per_base: number;
	fat_per_base: number;
	sugar_per_base: number;
	fiber_per_base: number;
	status: string;
	image_path?: string;
	servings: FoodServing[];
	aliases?: FoodAlias[];
	score?: number;
	match_type?: string;
}

export interface FoodServing {
	id: string;
	food_id: string;
	name: string;
	amount_in_base: number;
	is_default: number;
}

export interface FoodAlias {
	id: string;
	food_id: string;
	alias: string;
	alias_normalized: string;
}

export interface FoodEntry {
	id: string;
	user_id: string;
	food_id?: string;
	meal_type: string;
	entry_date: string;
	entry_type: string;
	quantity: number;
	unit: string;
	serving_description?: string;
	snapshot_food_name: string;
	snapshot_serving_label?: string;
	snapshot_grams?: number;
	snapshot_calories: number;
	snapshot_protein: number;
	snapshot_carbs: number;
	snapshot_fat: number;
	snapshot_sugar: number;
	snapshot_fiber: number;
	source: string;
	entry_method: string;
	raw_text?: string;
	confidence_score?: number;
	note?: string;
	food_image_path?: string;
	created_at: string;
}

export interface DailyTotals {
	total_calories: number;
	total_protein: number;
	total_carbs: number;
	total_fat: number;
	total_sugar: number;
	total_fiber: number;
	entry_count: number;
}

export interface Goal {
	id: string;
	user_id: string;
	start_date: string;
	end_date?: string;
	calories: number;
	protein: number;
	carbs: number;
	fat: number;
	sugar: number;
	fiber: number;
	is_active: number;
}

export interface MealTemplate {
	id: string;
	user_id: string;
	name: string;
	meal_type?: string;
	is_favorite: number;
	items: MealTemplateItem[];
}

export interface MealTemplateItem {
	id: string;
	food_id: string;
	quantity: number;
	unit: string;
	snapshot_food_name: string;
	snapshot_calories: number;
	snapshot_protein: number;
	snapshot_carbs: number;
	snapshot_fat: number;
	snapshot_sugar: number;
	snapshot_fiber: number;
}

export interface QueueItem {
	id: string;
	user_id: string;
	raw_text: string;
	proposed_food_id?: string;
	candidates_json?: string;
	confidence: number;
	meal_type?: string;
	entry_date?: string;
	source?: string;
	created_at: string;
}

export interface ExternalFood {
	name: string;
	brand?: string;
	barcode?: string;
	calories_per_100g: number;
	protein_per_100g: number;
	carbs_per_100g: number;
	fat_per_100g: number;
	sugar_per_100g: number;
	fiber_per_100g: number;
	serving_size_text?: string;
	serving_grams?: number;
	source: string;
	relevance_score?: number;
}

export interface ResolveResult {
	resolution_type: 'matched' | 'confirm' | 'queued' | 'quick_add' | 'ai_estimated' | 'external_match';
	confidence: number;
	matched_food?: Food;
	candidate_foods: Food[];
	external_results: ExternalFood[];
	ai_estimate?: Record<string, unknown>;
	parsed: {
		quantity: number;
		unit: string;
		food_description: string;
		meal_type?: string;
		brand?: string;
		modifiers?: string;
		exclusions?: string;
	};
	raw_text: string;
	queue_id?: string;
	reason?: string;
}

export type MealType = 'breakfast' | 'lunch' | 'dinner' | 'snack';

export const MEAL_TYPES: MealType[] = ['breakfast', 'lunch', 'dinner', 'snack'];

export const MEAL_LABELS: Record<MealType, string> = {
	breakfast: 'B',
	lunch: 'L',
	dinner: 'D',
	snack: 'S'
};
