import { getReadingPlatformAPI } from './generated/api'
import type { ResultUserInfoResponse } from './generated/model'

// Orval 生成的完整 API 客户端
export const readingApi = getReadingPlatformAPI()

// 通用工具类型：根据方法名拿到返回 Promise 的结果类型
export type ApiResultOf<K extends keyof ReturnType<typeof getReadingPlatformAPI>> =
  Awaited<ReturnType<ReturnType<typeof getReadingPlatformAPI>[K]>>

// 如果后端统一使用 Result<T> 包裹，这个类型可以从中解包出 data
export type UnwrapResult<R> = R extends { data: infer D } ? D : R

// 针对分页 Result<PageResult<XXX>> 的统一解包类型
export type PageDataOf<R> = UnwrapResult<R> extends {
  items: any[]
  total: number
  page: number
  pageSize: number
}
  ? UnwrapResult<R>
  : never

// 常用 Orval 分页结果类型别名（便于在各模块中统一使用）
export type GetTenantPageResult = PageDataOf<ApiResultOf<'getTenantPage'>>
export type GetTaskPageResult = PageDataOf<ApiResultOf<'getTaskPage'>>
export type GetTaskPage1Result = PageDataOf<ApiResultOf<'getTaskPage1'>>
export type GetTeacherPageResult = PageDataOf<ApiResultOf<'getTeacherPage'>>
export type GetStudentPageResult = PageDataOf<ApiResultOf<'getStudentPage'>>
export type GetSchedulePlansResult = PageDataOf<ApiResultOf<'getSchedulePlans'>>
export type GetSchedulePlans1Result = PageDataOf<ApiResultOf<'getSchedulePlans1'>>
export type GetPackagesResult = PageDataOf<ApiResultOf<'getPackages'>>
export type GetPackages1Result = PageDataOf<ApiResultOf<'getPackages1'>>
export type GetMyNotificationsResult = PageDataOf<ApiResultOf<'getMyNotifications'>>
export type GetMyNotifications1Result = PageDataOf<ApiResultOf<'getMyNotifications1'>>
export type GetMyNotifications2Result = PageDataOf<ApiResultOf<'getMyNotifications2'>>

// 示例：当前登录用户信息的解包类型
export type CurrentUserInfo = UnwrapResult<ResultUserInfoResponse>

