import type { VillageVO, VillageForm, VillageQuery, 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 villageList(params?: VillageQuery) {
  return requestClient.get<PageResult<VillageVO>>('/biz/village/list', { params });
}

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

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

/**
 * 导出包村差旅补助列表
 * @param params
 * @returns 包村差旅补助列表
 */
export function villageExport(params?: VillageQuery) {
  return commonExport('/biz/village/export', params ?? {});
}

/**
 * 查询包村差旅补助详情
 * @param id id
 * @returns 包村差旅补助详情
 */
export function villageInfo(id: ID) {
  return requestClient.get<VillageVO>(`/biz/village/${id}`);
}

/**
 * 新增包村差旅补助
 * @param data
 * @returns void
 */
export function villageAdd(data: VillageForm) {
  return requestClient.postWithMsg<void>('/biz/village', data);
}

/**
 * 更新包村差旅补助
 * @param data
 * @returns void
 */
export function villageUpdate(data: VillageForm) {
  return requestClient.putWithMsg<void>('/biz/village', data);
}

/**
 * 删除包村差旅补助
 * @param id id
 * @returns void
 */
export function villageRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/biz/village/${id}`);
}
