import { get, post } from '@/lib/request'
import { USE_MOCK, delay } from '@/mock'
import { mockMenuTree } from '@/mock/system/menus'
import type { SystemMenu } from '../system'

const BASE_URL = '/sys/menu'

export async function getMenuTree() {
  if (USE_MOCK) { await delay(); return mockMenuTree }
  return get<SystemMenu[]>(`${BASE_URL}/list`)
}

export async function getMenuByRole(id: string) {
  if (USE_MOCK) { await delay(); return mockMenuTree }
  return post<SystemMenu[]>(`${BASE_URL}/byRole`, { id })
}

export async function createMenu(data: Partial<SystemMenu>) {
  if (USE_MOCK) { await delay(); return null }
  return post<null>(`${BASE_URL}/create`, data)
}

export async function updateMenu(data: Partial<SystemMenu> & { id: string }) {
  if (USE_MOCK) { await delay(); return null }
  return post<null>(`${BASE_URL}/update`, data)
}

export async function deleteMenu(ids: string[]) {
  if (USE_MOCK) { await delay(); return null }
  return post<null>(`${BASE_URL}/delete`, { ids })
}
