import type { SalaryVO, SalaryForm, SalaryQuery, 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 salaryList(params?: SalaryQuery) {
  return requestClient.get<PageResult<SalaryVO>>('/biz/salary/list', { params });
}

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

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

/**
 * 导出工资明细列表
 * @param params
 * @returns 工资明细列表
 */
export function salaryExport(params?: SalaryQuery) {
  return commonExport('/biz/salary/export', params ?? {});
}

/**
 * 查询工资明细详情
 * @param id id
 * @returns 工资明细详情
 */
export function salaryInfo(id: ID) {
  return requestClient.get<SalaryVO>(`/biz/salary/${id}`);
}

/**
 * 新增工资明细
 * @param data
 * @returns void
 */
export function salaryAdd(data: SalaryForm) {
  return requestClient.postWithMsg<void>('/biz/salary', data);
}

/**
 * 更新工资明细
 * @param data
 * @returns void
 */
export function salaryUpdate(data: SalaryForm) {
  return requestClient.putWithMsg<void>('/biz/salary', data);
}

/**
 * 删除工资明细
 * @param id id
 * @returns void
 */
export function salaryRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/biz/salary/${id}`);
}
