import { get, post } from '../../http'

export async function addMeaningApi(data: any) {
  return await post<any>('/word/addMeaning', data)
}

export async function fixTextBookWordApi(textbookId?: any) {
  const url = textbookId
    ? `/textbookWord/fixData?textbookId=${encodeURIComponent(textbookId)}`
    : '/textbookWord/fixData'
  return await post<any>(url, undefined, {
    timeout: 1000 * 60 * 5,
    ...(textbookId !== undefined && textbookId !== null && textbookId !== ''
      ? { params: { textbookId } }
      : {}),
  })
}

// 获取单词书中的单词
export type GetTextBookWordApi = {
  bind: any
  current: any
  keyword: any
  size: any
  textbookId: any
}
export type TextBookWord = {
  id: any
  levelName: string
  levelNum: number
  meaningId: any
  stageName: string
  textbookId: any
  textbookName: string
  versionName: string
  wordDesc: string
  wordId: any
  wordSpell: string
}
export type TextBookWordPageData = {
  current: number
  rows: TextBookWord[]
  size: number
  totalPage: number
  totalRows: number
}
export async function getTextBookWordsApi(
  params: GetTextBookWordApi,
): Promise<TextBookWordPageData> {
  return await get<any>('/textbookWord/check/list', params)
}

// 获取教材版本
export type TextBookVersion = {
  id: any
  name: string
}
export async function getTextBookVersionsApi(
  stage: any,
): Promise<TextBookVersion[]> {
  return await get<any>(`/textbookVersion/list/${stage}`)
}

// 获取教材
export type TextBook = {
  allWordCount: number
  id: any
  name: string
  singleWordCount: number
}
export async function getTextBooksApi(versionId: any): Promise<TextBook[]> {
  return await get<any>(`/textbook/list`, { versionId })
}

// 根据教材同步单词数据
export async function syncWordByTextBookApi(textbookId: any) {
  return await post<any>('/xkw/word/sync', null, {
    params: { textbookId },
    timeout: 1000 * 60 * 10,
  })
}
