/** 前端 EPS 类型 */
export type EpsApiItem = {
  method: string
  path: string
  summary: string
  prefix: string
  ignoreToken: boolean
  ignorePerms: boolean
  perms: string[]
}

export type EpsColumn = {
  propertyName: string
  /** drizzle dataType：string / number / boolean / date */
  type: string
  /** drizzle columnType：PgVarchar / PgText / PgInteger / PgNumeric … */
  columnType?: string
  sqlType?: string
  length?: string
  precision?: number
  scale?: number
  comment?: string
  nullable?: boolean
  hasDefault?: boolean
  dict?: string | string[]
  /** 物理表名，供 field.{table}.{prop} */
  table?: string
  source?: string
}

export type EpsEntity = {
  module: string
  side: string
  prefix: string
  /** 关联实体/表名（可选）；中间列展示用 info.type.name 或 prefix 末段 */
  name?: string
  info?: {
    type: {
      /** 控制器路径末段，对应文件名（如 dict-info） */
      name: string
      description: string
    }
  }
  api: EpsApiItem[]
  columns: EpsColumn[]
  pageColumns: EpsColumn[]
  pageQueryOp?: {
    keyWordLikeFields?: unknown[]
    fieldEq?: unknown[]
    fieldLike?: unknown[]
    fieldArray?: unknown[]
    fieldRange?: unknown[]
  }
  /** Controller api 含 dataI18n：本实体参与业务数据翻译 */
  dataI18n?: boolean
  /** direct 字段名（语言 Tab 列）；来自 Controller dataI18nFields / 推断 */
  dataI18nFields?: string[]
  dataI18nTables?: string[]
}

export type EpsModuleMap = Record<string, EpsEntity[]>

/** EPS 开放接口完整载荷 */
export type EpsDictFlatRow = {
  id: number
  name: string
  typeId: number
  parentId?: number | null
  orderNum?: number
  value?: unknown
}

export type EpsPayload = {
  /** 服务端 vome.eps；写入打包 eps.json，生产仅 true 时前端可再请求 */
  eps?: boolean
  modules: EpsModuleMap
  dict: Record<string, EpsDictFlatRow[]>
}

/** 菜单「自动添加权限」行 */
export type AutoPermRow = {
  enabled: boolean
  name: string
  perm: string
}
