import type { AxiosRequestConfig } from 'axios'
import type { BaseDefine, MultipleQuery, MultipleResult, BaseMultiplePageQuery } from './api-types/base'
import { User } from './api-types/user'
import { Role } from './api-types/role'
import { Exam } from './api-types/exam'
import { Subject } from './api-types/subject'
import { Statistics } from './api-types/statistics'
import { Question } from './api-types/question'
import { Marking } from './api-types/marking'
import { System } from './api-types/system'
import { Message } from './api-types/message'
import { ForceCheck } from './api-types/forceCheck'
import { Expert } from './api-types/expert'

export type ApiMap = User.ApiMap &
  Role.ApiMap &
  Exam.ApiMap &
  Subject.ApiMap &
  Statistics.ApiMap &
  Question.ApiMap &
  Marking.ApiMap &
  System.ApiMap &
  Message.ApiMap &
  ForceCheck.ApiMap &
  Expert.ApiMap

export type ApiKeys = keyof ApiMap
export { MultipleQuery, MultipleResult, BaseMultiplePageQuery }

export type DefineApiModule<M extends object> = {
  [k in keyof M]: string | (AxiosRequestConfig & { url: string })
}

export type ExtractApiParams<T extends ApiKeys> = ApiMap[T] extends BaseDefine<infer P, any> ? P : never

export type ExtractMultipleApiParams<T extends ApiKeys> = ExtractApiParams<T> extends MultipleQuery<infer P> ? P : never

export type ExtractApiResponse<T extends ApiKeys> = ApiMap[T] extends BaseDefine<any, infer R> ? R : never

export type ExtractMultipleApiResponse<T extends ApiKeys> = ExtractApiResponse<T> extends MultipleResult<infer R>
  ? R
  : never
