import type { TrafficVO, TrafficForm, TrafficQuery, SalaryImportParam } from './model';

import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';

import { commonExport, ContentTypeEnum } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
* 查询公务交通补助列表
* @param params
* @returns 公务交通补助列表
*/
export function trafficList(params?: TrafficQuery) {
  return requestClient.get<PageResult<TrafficVO>>('/biz/traffic/list', { params });
}

/**
 * 从excel导入数据
 * @param data
 * @returns void
 */
export function salaryImportData(data: SalaryImportParam) {
  return requestClient.post<{ code: number; msg: string }>(
    '/biz/traffic/importData',
    data,
    {
      headers: {
        'Content-Type': ContentTypeEnum.FORM_DATA,
      },
      isTransformResponse: false,
    },
  );
}

/**
 * 下载导入模板
 * @returns blob
 */
export function downloadImportTemplate() {
  return requestClient.post<Blob>(
    '/biz/traffic/importTemplate',
    {},
    {
      isTransformResponse: false,
      responseType: 'blob',
    },
  );
}

/**
 * 导出公务交通补助列表
 * @param params
 * @returns 公务交通补助列表
 */
export function trafficExport(params?: TrafficQuery) {
  return commonExport('/biz/traffic/export', params ?? {});
}

/**
 * 查询公务交通补助详情
 * @param id id
 * @returns 公务交通补助详情
 */
export function trafficInfo(id: ID) {
  return requestClient.get<TrafficVO>(`/biz/traffic/${id}`);
}

/**
 * 新增公务交通补助
 * @param data
 * @returns void
 */
export function trafficAdd(data: TrafficForm) {
  return requestClient.postWithMsg<void>('/biz/traffic', data);
}

/**
 * 更新公务交通补助
 * @param data
 * @returns void
 */
export function trafficUpdate(data: TrafficForm) {
  return requestClient.putWithMsg<void>('/biz/traffic', data);
}

/**
 * 删除公务交通补助
 * @param id id
 * @returns void
 */
export function trafficRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/biz/traffic/${id}`);
}
