import { serialize } from 'object-to-formdata'
import { IQueryCommon, IRes, IResult } from '@/api/common'
import axios from '@/utils/request'
import { base, IRainfall } from './common'
import { ElUploadInternalRawFile } from 'element-ui/types/upload'

const uris = {
  base: `${base}/rainfall`,
  page: `${base}/rainfall/page`,
  del: `${base}/rainfall/deleteByIds`,
  import: `${base}/rainfall/batchData`
}

// export const addRainfall = (data: Omit<IRainfall, 'id'>) =>
//   axios.request<IRes<boolean>>({
//     url: uris.base,
//     method: 'post',
//     data: serialize(data, { dotsForObjectNotation: true, noFilesWithArrayNotation: true })
//   })

// export const deleteRainfall = (id: string) =>
//   axios.request<IRes<boolean>>({ url: `${uris.base}/${id}`, method: 'delete' })

// export const updateRainfall = (data: IRainfall) =>
//   axios.request<IRes<boolean>>({
//     url: uris.base,
//     method: 'put',
//     data: serialize(data, { dotsForObjectNotation: true, noFilesWithArrayNotation: true })
//   })

// export const getRainfall = (id: string) =>
//   axios.request<IResult<IRainfall>>({ url: `${uris.base}/${id}`, method: 'get' })

export const rainFallPage = (params: Partial<IRainfall & IQueryCommon>) =>
  axios.request<IRes<IRainfall[]>>({ url: uris.page, method: 'get', params })

// export const deleteRainfallBatch = (ids: string) =>
//   axios.request<IRes<boolean>>({ url: uris.del, method: 'delete', params: { ids } })

export const importRainfall = (data: { file: ElUploadInternalRawFile }) =>
  axios.request<IRes<boolean>>({
    url: uris.import,
    method: 'post',
    data: serialize(data, { dotsForObjectNotation: true, noFilesWithArrayNotation: true })
  })
