import type { Filter, FilterImportParam, FilterQuery } from './model';

import type { BaseResult } from '#/api/base-result';

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

enum Api {
  baseFilter = '/gasOilFilter/filter',
  filterDelete = '/gasOilFilter/filter/',
  filterExport = '/gasOilFilter/filter/export',
  filterImport = '/gasOilFilter/filter/import',
  filterInfo = '/gasOilFilter/filter/',
  filterList = '/gasOilFilter/filter/list',
  filterLogs = '/gasFilterMaintenanceLog/log/list',
}

// 返回日志
export function getFilterLogs(params?: any) {
  return requestClient.get<BaseResult<any>>(Api.filterLogs, { params });
}

// 过滤器列表接口
export function getFilterList(params?: FilterQuery) {
  return requestClient.get<BaseResult<Filter[]>>(Api.filterList, { params });
}

// 获取单个过滤器详细信息
export function getFilterDetail(id: number) {
  return requestClient.get<BaseResult<Filter>>(`${Api.filterInfo}${id}`);
}

// 删除过滤器
export function deleteFilter(ids: number | number[]) {
  return requestClient.delete(
    `${Api.filterDelete}${Array.isArray(ids) ? ids.join(',') : ids}`,
  );
}

// 导出场站过滤器列表
export function filterExport(data: Partial<Filter>) {
  return commonExport(Api.filterExport, data);
}

// 导入场站过滤器
export function filterImportData(data: FilterImportParam) {
  return requestClient.put<BaseResult<any>>(Api.filterImport, data, {
    headers: {
      'Content-Type': ContentTypeEnum.FORM_DATA,
    },
  });
}

// 创建过滤器
export function createFilter(data: Filter) {
  return requestClient.post<BaseResult<any>>(Api.baseFilter, data);
}

// 更新过滤器
export function updateFilter(data: Filter) {
  return requestClient.put<BaseResult<any>>(Api.baseFilter, data);
}
