import { apiClient } from "./client";
import { ApiResponse } from "@/types/commonCode";

/**
 * 즐겨찾기 메뉴 API
 *
 * 백엔드 엔드포인트 ↔ DB-per-tenant 의 USER_MENU_FAVORITES 테이블.
 * 응답 행은 MENU_INFO 와 JOIN 된 형태 (menu_name_kor / menu_url / menu_icon 등 포함).
 */
export const favoritesAPI = {
  getList: async (): Promise<ApiResponse<Record<string, any>[]>> => {
    const res = await apiClient.get<ApiResponse<Record<string, any>[]>>("/favorites/menus");
    return res.data;
  },

  add: async (menuObjid: string | number): Promise<ApiResponse<Record<string, any>>> => {
    const res = await apiClient.post<ApiResponse<Record<string, any>>>(
      "/favorites/menus",
      { menu_objid: String(menuObjid) },
    );
    return res.data;
  },

  remove: async (menuObjid: string | number): Promise<ApiResponse<Record<string, any>>> => {
    const res = await apiClient.delete<ApiResponse<Record<string, any>>>(
      `/favorites/menus/${encodeURIComponent(String(menuObjid))}`,
    );
    return res.data;
  },
};
