import request from '@/utils/request'
import { ModuleKey } from '@/enums/ModuleEnum'

export interface PortalMenuItem {
  id: string
  title: string
  path: string
  icon?: string
  children?: PortalMenuItem[]
}

export interface PortalModuleMenu {
  module: ModuleKey
  commonMenus: PortalMenuItem[]
  moduleMenus: PortalMenuItem[]
}

/**
 * 新门户菜单接口（后端待提供）
 * 约定：返回“模块 + 菜单树”聚合结构，替代旧查询菜单接口
 */
export const fetchPortalMenus = () => {
  return request({
    url: '/sys/portal/menu/tree',
    method: 'post',
  })
}

/**
 * 接口未就绪时的本地 mock，方便先跑通导航壳。
 */
export const getPortalMenusMock = (): PortalModuleMenu[] => ([
  {
    module: ModuleKey.HOME,
    commonMenus: [
      { id: 'home-dashboard', title: '首页', path: '/home/dashboard', icon: 'dashboard' },
      { id: 'home-otr-role', title: '角色管理', path: '/otr/system/role', icon: 'peoples' },
      { id: 'home-sales-index', title: '销售首页', path: '/index', icon: 'chart' },
    ],
    moduleMenus: [],
  },
  {
    module: ModuleKey.OTR,
    commonMenus: [],
    moduleMenus: [
      {
        id: 'otr-system',
        title: '系统管理',
        path: '/otr/system',
        icon: 'system',
        children: [
          { id: 'otr-system-user', title: '员工管理', path: '/otr/system/user', icon: 'user' },
          { id: 'otr-system-role', title: '角色管理', path: '/otr/system/role', icon: 'peoples' },
          { id: 'otr-system-menu', title: '菜单管理', path: '/otr/system/menu', icon: 'tree-table' },
        ],
      },
    ],
  },
  {
    module: ModuleKey.SALES,
    commonMenus: [],
    moduleMenus: [
      { id: 'sales-index', title: '销售首页', path: '/index', icon: 'dashboard' },
      { id: 'sales-clue-add', title: '新增线索', path: '/clue/add', icon: 'edit' },
      { id: 'sales-customer-add', title: '创建客户', path: '/customer/addCustomer', icon: 'user' },
    ],
  },
  { module: ModuleKey.PROJECT, commonMenus: [], moduleMenus: [] },
  { module: ModuleKey.SALARY, commonMenus: [], moduleMenus: [] },
  { module: ModuleKey.WEBSITE, commonMenus: [], moduleMenus: [] },
])

