import request from '@/utils/request'

/**
 * 菜单模块接口定义
 */
export interface MenuItem {
  menuId: string
  menuName: string
  menuCode: string
  moduleCode: string
  cicon: string
  chref: string
  ftenantId: string
  fflowId: string | null
  fflowTaskId: string | null
  fflowState: string | null
}

export interface ModuleItem {
  moduleName: string
  moduleCode: string
  icon: string
  href: string
  menus: MenuItem[]
}

export interface MenuResponse {
  code: number
  message: string
  result: ModuleItem[]
}

/**
 * 获取模块菜单数据
 */
export const getModuleMenus = async (): Promise<ModuleItem[]> => {
  const response = await request.get<MenuResponse>('/Sys/login/getModules')
  
  if (response.code !== 200) {
    console.error('获取菜单数据失败:', response.message)
    throw new Error(`获取菜单失败: ${response.message}`)
  }
  
  return response.result || []
}
