import {
  get,
  post,
} from '@/common/utils/http-util.ts'
import { saveFile } from '@/common/app'

export default {
  paging(data: TplTypes.SearchTplParam) {
    return get<G.PageResult<TplTypes.SearchTplResult>>('/tpl/paging', data)
  },
  detail(id: string) {
    return get<TplTypes.SearchTplResult>('/tpl/detail', {id})
  },
  add(data: TplTypes.AddTplParam) {
    return post('/tpl/add', data)
  },
  modify(data: TplTypes.ModifyTplParam) {
    return post('/tpl/modify', data)
  },
  del(ids: string[]) {
    return post('/tpl/del', ids)
  },
  listAll(lang: string) {
    return get<TplTypes.SearchTplResult[]>('/tpl/list_all', {lang})
  },
  preview(lang: string, tableName: string, data: Record<string, any>) {
    return post<TplTypes.CodeInfo>('/tpl/preview', data, {lang, tableName})
  },
  download(lang: string, tableName: string, data: Record<string, any>) {
    return saveFile(post('/tpl/download', data, {lang, tableName}, {responseType: 'arraybuffer'}))
  },
}
