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

export async function getMenuTree() {
  if (USE_MOCK) { await delay(); return mockResponse(mockMenuTree) }
  return get<{ code: number; data: SystemMenu[]; msg: string }>('/system/menus/tree')
}

export async function createMenu(data: Partial<SystemMenu>) {
  if (USE_MOCK) { await delay(); return mockResponse(null, '创建成功') }
  return post<{ code: number; data: null; msg: string }>('/system/menus', data)
}

export async function updateMenu(id: string, data: Partial<SystemMenu>) {
  if (USE_MOCK) { await delay(); return mockResponse(null, '更新成功') }
  return put<{ code: number; data: null; msg: string }>(`/system/menus/${id}`, data)
}

export async function deleteMenu(id: string) {
  if (USE_MOCK) { await delay(); return mockResponse(null, '删除成功') }
  return del<{ code: number; data: null; msg: string }>(`/system/menus/${id}`)
}
