import { defHttp } from '/@/utils/http/axios';

enum Api {
  list = '/print/template/list',
  add = '/print/template/add',
  edit = '/print/template/edit',
  deleteOne = '/print/template/delete',
  deleteBatch = '/print/template/deleteBatch',
  queryById = '/print/template/queryById',
  saveJson = '/print/template/saveJson',
}

export const list = (params) => defHttp.get({ url: Api.list, params });

export const add = (params) => defHttp.post({ url: Api.add, params });

export const edit = (params) => defHttp.put({ url: Api.edit, params });

export const deleteOne = (params, handleSuccess?) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess?.();
  });
};

export const batchDelete = (params, handleSuccess?) => {
  return defHttp.delete({ url: Api.deleteBatch, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess?.();
  });
};

export const queryById = (id: string) => defHttp.get({ url: Api.queryById, params: { id } });

export const saveJson = (data: { id: string; templateJson: string }) =>
  defHttp.post({ url: Api.saveJson, data }, { successMessageMode: 'message' });
