import axios from "@/config/axios";
import type {
  CreateCategoryType,
  CreateFoodType,
  GetCategoriesResponseType,
  GetFoodDetailsResponseType,
  GetFoodsParams,
  GetFoodsResponseType,
} from "../types/Types";

export const createFood = async (params: CreateFoodType) => {
  const { data } = await axios.post(`/foods`, params);
  return data;
};

export const getFoods = async (
  params?: GetFoodsParams
): Promise<GetFoodsResponseType> => {
  const { data } = await axios.get<GetFoodsResponseType>(`/foods`, { params });
  return data;
};

export const getFoodDetails = async (
  id: string
): Promise<GetFoodDetailsResponseType> => {
  const { data } = await axios.get<GetFoodDetailsResponseType>(`/foods/${id}`);
  return data;
};

export const updateFood = async (id: string, params: CreateFoodType) => {
  const { data } = await axios.patch(`/foods/${id}`, params);
  return data;
};

export const getCategories = async (): Promise<GetCategoriesResponseType> => {
  const { data } = await axios.get<GetCategoriesResponseType>(`/categories`);
  return data;
};

export const deleteFood = async (id: string) => {
  const { data } = await axios.delete(`/foods/${id}`);
  return data;
};

export const createCategory = async (params: CreateCategoryType) => {
  const { data } = await axios.post(`/categories`, params);
  return data;
};

export const deleteCategory = async (id: string) => {
  const { data } = await axios.delete(`/categories/${id}`);
  return data;
};

export const updateCategory = async (
  id: string,
  params: CreateCategoryType
) => {
  const { data } = await axios.patch(`/categories/${id}`, params);
  return data;
};
