import { http } from '../http'
// 词典

interface SearchWordParams {
  keyword: string
  current?: number
  size?: number
  [key: string]: any
}

interface SearchHistoryParams {
  current?: number
  size?: number
  stageState?: number
  [key: string]: any
}

interface AddSearchHistoryData {
  wordId: string
  searchValue: string
  stageState: number
  wordSpell: string
  wordZnDesc?: string
  spell?: string
}

/**
 * @description: 词典搜索
 * @param {SearchWordParams} params：搜索参数
 * @return {*}
 */
const searchWordApi = (params: SearchWordParams) => {
  return http.request({
    url: '/word/search',
    params,
  })
}

/**
 * @description: 搜索历史
 * @param {SearchHistoryParams} params：查询参数
 * @return {*}
 */
const getSearchHistoryApi = (params: SearchHistoryParams) => {
  return http.request({
    url: '/searchLog/list',
    params,
  })
}

/**
 * @description: 搜索历史-新增
 * @param {AddSearchHistoryData} data：搜索历史数据
 * @return {*}
 */
const addSearchHistoryApi = (data: AddSearchHistoryData) => {
  return http.request({
    url: '/searchLog',
    data,
    method: 'POST',
  })
}

/**
 * @description: 搜索历史-删除
 * @param {*} params：
 * @return {*}
 */
const deleteSearchHistoryApi = () => {
  return http.request({
    url: '/searchLog/deleteAll',
    method: 'DELETE',
  })
}

const dictionariesApi = {
  searchWordApi,
  getSearchHistoryApi,
  addSearchHistoryApi,
  deleteSearchHistoryApi,
}

export default dictionariesApi
