/** 链式 service 叶子节点 */
export type ServiceRequestOptions = {
  url?: string
  method?: string
  data?: unknown
  params?: Record<string, unknown>
  /** 透传 HTTP 超时；默认由 request 客户端处理（5s） */
  timeoutMs?: number
}

export type ServiceLeaf = {
  namespace: string
  permission: Record<string, string>
  _permission: Record<string, boolean>
  request: (options?: ServiceRequestOptions) => Promise<unknown>
  page?: (
    data?: Record<string, unknown>,
    options?: Pick<ServiceRequestOptions, 'timeoutMs'>,
  ) => Promise<{
    list: Record<string, unknown>[]
    pagination: { page: number; size: number; total: number }
  }>
  list?: (
    data?: Record<string, unknown>,
    options?: Pick<ServiceRequestOptions, 'timeoutMs'>,
  ) => Promise<Record<string, unknown>[]>
  info?: (data: { id: number | string }) => Promise<Record<string, unknown>>
  add?: (data: Record<string, unknown>) => Promise<unknown>
  update?: (data: Record<string, unknown>) => Promise<unknown>
  delete?: (data: {
    ids: Array<number | string>
    force?: boolean
  }) => Promise<unknown>
  restore?: (data: { ids: Array<number | string> }) => Promise<unknown>
  [method: string]: unknown
}

/** 嵌套树：service.base.user（动态键，运行时由 EPS 填充） */
export type ServiceTree = {
  request: (options?: ServiceRequestOptions) => Promise<unknown>
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  [key: string]: any
}
