import axios from "../../../config/axios";
import {
  CreateGroupIconType,
  CreateIconType,
  GroupIconsResponse,
  IconsResponse,
  ReportsResponse,
  RestaurantsResponse,
  RestaurantResponse,
  RestaurantSmsCountResponse,
  AddAdminRestaurantType,
  SystemRolesResponse,
  RestaurantAdminsResponse,
  UpdateRestaurantType,
} from "../types/Types";

export const getIcons = async (): Promise<IconsResponse> => {
  const { data } = await axios.get("/admin/dmenu/icons");
  return data;
};

export const createGroupIcon = async (params: CreateGroupIconType) => {
  const { data } = await axios.post("/admin/dmenu/icons/groups", params);
  return data;
};

export const getGroupIcons = async (): Promise<GroupIconsResponse> => {
  const { data } = await axios.get("/admin/dmenu/icons/groups");
  return data;
};

export const deleteGroupIcon = async (id: string) => {
  const { data } = await axios.delete(`/admin/dmenu/icons/groups/${id}`);
  return data;
};

export const createIcon = async (params: CreateIconType) => {
  const { data } = await axios.post("/admin/dmenu/icons", params);
  return data;
};

export const deleteIcon = async (id: string) => {
  const { data } = await axios.delete(`/admin/dmenu/icons/${id}`);
  return data;
};

export const getReports = async (): Promise<ReportsResponse> => {
  const { data } = await axios.get("/admin/dmenu/contacts");
  return data;
};

export const getRestaurants = async (
  page: number = 1,
  limit: number = 10
): Promise<RestaurantsResponse> => {
  const { data } = await axios.get(
    `/admin/dmenu/restaurants?page=${page}&limit=${limit}`
  );
  return data;
};

export const getRestaurantAdmins = async (
  restaurantId: string
): Promise<RestaurantAdminsResponse> => {
  const { data } = await axios.get(
    `/admin/dmenu/restaurants/${restaurantId}/admins`
  );
  return data;
};

export const getRestaurantSmsCount = async (): Promise<
  RestaurantSmsCountResponse
> => {
  const { data } = await axios.get(`/admin/dmenu/restaurants/sms-count`);
  return data;
};

export const deleteRestaurantAdmin = async (
  restaurantId: string,
  adminId: string
) => {
  const { data } = await axios.delete(
    `/admin/dmenu/restaurants/${restaurantId}/admins/${adminId}`
  );
  return data;
};

export const addAdminRestaurant = async (params: AddAdminRestaurantType) => {
  const { data } = await axios.post(
    `/admin/dmenu/restaurants/${params.restaurantId}/admins`,
    params
  );
  return data;
};

export const getSystemRoles = async (): Promise<SystemRolesResponse> => {
  const { data } = await axios.get(`/admin/dmenu/system-roles`);
  return data;
};

export const updateRestaurant = async (
  id: string,
  params: UpdateRestaurantType
) => {
  const { data } = await axios.patch(`/admin/dmenu/restaurants/${id}`, params);
  return data;
};

export const getRestaurant = async (
  id: string
): Promise<RestaurantResponse> => {
  const { data } = await axios.get(`/admin/dmenu/restaurants/${id}`);
  return data;
};

export const hardDeleteRestaurant = async (id: string) => {
  const { data } = await axios.delete(
    `/admin/dmenu/restaurants/${id}/hard-delete`
  );
  return data;
};
