import type { MenuEntity, PageConfig } from '@vben/types';

import { parseQueryValues } from '@vben/utils';

import { requestClient } from '#/api/request';

interface MenuPartialEntity extends Partial<Omit<MenuEntity, 'menu_name'>> {
  menu_name?: string;
}

interface MenuQueryParams extends MenuPartialEntity, PageConfig {}

/**
 * 菜单信息_列表
 */
export async function getMenuListApi(params: MenuQueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=83', {
    ...params,
  });
}

/**
 * 菜单信息_详情
 */
export async function getMenuDetailApi(data: { menu_id: number }) {
  return requestClient.post<any>(
    '/api/query/view?pagevalue=84',
    {
      ...parseQueryValues(data),
    },
    { formatData: true },
  );
}

/**
 * 菜单信息_新增
 */
export async function addMenuApi(data: MenuEntity) {
  return requestClient.post<any>('/api/add?pagevalue=85', { ...data });
}

/**
 * 菜单信息_编辑
 */
export async function editMenuApi(data: MenuEntity) {
  return requestClient.post<any>('/api/up?pagevalue=86', { ...data });
}

/**
 * 菜单信息_删除
 */
export async function deleteMenuApi(data: { 'menu_id.value': number }) {
  return requestClient.post<any>('/api/del?pagevalue=87', { ...data });
}

/**
 * 初始化权限
 */
export async function initPermissionApi() {
  return requestClient.post<any>('/api/sys/initialize?pagevalue=18');
}
