import type { AxiosResponse } from 'axios'
import type { PageInfo, Result } from '@cacp/ui'
import request from '@/utils/request'
import download from 'js-file-download'

import type {EntryInfo, Entry, EntryQuery, EntryQuery1} from '@/types/analyze/goodsEntry'

const contextPath = '/analyze/goodsEntry'
//获取单据
export async function getEntryHead(entryId: string): Promise<Result<EntryInfo>> {
  const res: AxiosResponse<Result<EntryInfo>> = await request.get(`${contextPath}/get-entry?entryId=${entryId}`)
  return res.data
}

// 查询危险品报关单头列表
export async function getList(query: EntryQuery): Promise<Result<PageInfo<Entry>>> {
  const res: AxiosResponse<Result<PageInfo<Entry>>> = await request.post(`${contextPath}/get-list`, query)
  return res.data
}

//获取单据列表
export async function exportList(query: EntryQuery1): Promise<void> {
  const res: AxiosResponse<Result<any>> = await request.post(`${contextPath}/goods-export`, query, {
    responseType: 'arraybuffer'
  })
  if (res.status === 200) {
    download(res.request.response, "危险货物组合查询数据.xlsx", 'application/octet-stream')
  }
}
