import { api } from "@/api/axiosInstance";
import type { MealPlanEntry, ShoppingListItem, UpsertMealPlanEntryInput } from "@/types/meal-plan.types";

export async function fetchMealPlanEntries(from: string, to: string): Promise<MealPlanEntry[]> {
  const { data } = await api.get<MealPlanEntry[]>("/meal-plan", { params: { from, to } });
  return data;
}

export async function upsertMealPlanEntry(input: UpsertMealPlanEntryInput): Promise<MealPlanEntry> {
  const { data } = await api.put<MealPlanEntry>("/meal-plan", input);
  return data;
}

export async function deleteMealPlanEntry(id: number): Promise<void> {
  await api.delete(`/meal-plan/${id}`);
}

export async function fetchShoppingList(from: string, to: string): Promise<ShoppingListItem[]> {
  const { data } = await api.get<ShoppingListItem[]>("/meal-plan/shopping-list", { params: { from, to } });
  return data;
}
