import { apiFetch } from '@/src/api/client';
import type {
  MealPlanEntry,
  ShoppingListItem,
  UpsertMealPlanEntryInput,
} from '@/src/types/meal-plan';

export async function fetchMealPlanEntries(from: string, to: string): Promise<MealPlanEntry[]> {
  return apiFetch<MealPlanEntry[]>(`/meal-plan?from=${from}&to=${to}`);
}

export async function upsertMealPlanEntry(input: UpsertMealPlanEntryInput): Promise<MealPlanEntry> {
  return apiFetch<MealPlanEntry>('/meal-plan', { method: 'PUT', body: input });
}

export async function deleteMealPlanEntry(id: number): Promise<void> {
  await apiFetch(`/meal-plan/${id}`, { method: 'DELETE' });
}

export async function fetchShoppingList(from: string, to: string): Promise<ShoppingListItem[]> {
  return apiFetch<ShoppingListItem[]>(`/meal-plan/shopping-list?from=${from}&to=${to}`);
}
