/**
 * 项目：中核预埋件检测
 * @Author: xiongwei
 * @Date: 2024-11-15 11:50:00
 */

import { defHttp } from '@/utils/http/axios';
import {
  Task,
  TaskParams,
  TaskPageResult,
} from '../model/task';

const baseApi = '/v1/data/task';

/**
 * 新增
 */
export const add = (entity: Task) =>
  defHttp.post<Task>({ url: `${baseApi}/`, data: entity });

/**
 * 更新
 */
export const update = (entity: Task, updateAllFields = false) =>
  defHttp.put<Task>({ url: `${baseApi}/`, data: entity, params: { updateAllFields } });

/**
 * 删除
 */
export const remove = (id: any) =>
  defHttp.delete<number>({ url: `${baseApi}/${id}` });

/**
 * 分页查询
 */
export const search = (params?: TaskParams) =>
  defHttp.get<TaskPageResult>({ url: `${baseApi}/search`, params });

/**
 * 列表查询
 */
export const all = (params?: TaskParams) =>
  defHttp.get<Task[]>({ url: `${baseApi}/all`, params });

/**
 * 通过主键查询
 */
export const getById = (id: any) =>
  defHttp.get<Task>({ url: `${baseApi}/${id}` });

/**
 * 单个查询
 */
export const getOne = (params?: TaskParams) =>
  defHttp.get<Task>({ url: `${baseApi}/one`, params });

/**
 * 批量删除
 */
export const batchRemove = (idList: Array<any>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-delete`, data: idList });

/**
 * 批量新增
 */
export const batchAdd = (entityList: Array<Task>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-save`, data: entityList });

/**
 * 批量更新
 */
export const batchUpdate = (entityList: Array<Task>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-update`, data: entityList });

/**
 * 查询数量
 */
export const count = (params?: TaskParams) =>
  defHttp.get<number>({ url: `${baseApi}/count`, params });

/**
 * 导入参数
 */
export const importByOCR = (base64ImageString: any) =>
  defHttp.post<boolean>({ url: `${baseApi}/ocr`, data: base64ImageString });
