import { Alova, url } from '../alova'

export const fetchTtsList = (num: string) => {
  const form = new FormData();
  form.append('num', num)
  return Alova.Get(url.ttsList, {
    headers: {
      'Content-Type': 'application/x-www-from-urlencoded; charset=UTF-8'
    },
    params: { num }
  })
}

export interface SaveTOTTSParams {
  document: string
  voiceType: string
  speed: number
  volume: number
  num: string
  type?: string
  id?: number
  name?: string
}

export const saveTOTTS = (params: SaveTOTTSParams) => {
  return Alova.Post(url.ttsSave, {
    ...params,
    speed: String(params.speed),
    volume: String(params.volume),
    //
    voiceType: String(params.type)
  })
}

export const saveTOSTT = (params: {
  id?: string
  num: string
  file: File
  name: string
}) => {
  const forms = new FormData()
  forms.append('file', params.file)
  forms.append('num', params.num)
  forms.append('name', params.name)
  params.id && forms.append('id', params.id)
  return Alova.Post(url.sttSave, forms)
}

export const deleteTTS = (params: { id: number; num: string }) => {
  return Alova.Post(url.ttsDel, {
    ...params
  })
}
