import type { HousingVO, HousingForm, HousingQuery, 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 housingList(params?: HousingQuery) {
  return requestClient.get<PageResult<HousingVO>>('/biz/housing/list', { params });
}

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

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

/**
 * 导出住房提租补贴列表
 * @param params
 * @returns 住房提租补贴列表
 */
export function housingExport(params?: HousingQuery) {
  return commonExport('/biz/housing/export', params ?? {});
}

/**
 * 查询住房提租补贴详情
 * @param id id
 * @returns 住房提租补贴详情
 */
export function housingInfo(id: ID) {
  return requestClient.get<HousingVO>(`/biz/housing/${id}`);
}

/**
 * 新增住房提租补贴
 * @param data
 * @returns void
 */
export function housingAdd(data: HousingForm) {
  return requestClient.postWithMsg<void>('/biz/housing', data);
}

/**
 * 更新住房提租补贴
 * @param data
 * @returns void
 */
export function housingUpdate(data: HousingForm) {
  return requestClient.putWithMsg<void>('/biz/housing', data);
}

/**
 * 删除住房提租补贴
 * @param id id
 * @returns void
 */
export function housingRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/biz/housing/${id}`);
}
