import Common from '../../common/Common.js';

// 查询当前公司全部打印机配置
export const queryAllPrinters = () => {
  const requestUrl = 'PrinterConfigurationResource/selectAll';
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'get',
      contentType: 'application/json',
      dataType: 'json',
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

// 根据id查询打印机配置
export const queryById = id => {
  const requestUrl = `PrinterConfigurationResource/selectById?id=${id}`;
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'get',
      contentType: 'application/json',
      dataType: 'json',
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

// 新增或修改打印机配置
export const saveOrUpdate = params => {
  const requestUrl = 'PrinterConfigurationResource/saveOrUpdate';
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'post',
      contentType: 'application/json',
      data: JSON.stringify(params),

      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

// 根据id删除打印机配置
export const deleteById = id => {
  const requestUrl = `PrinterConfigurationResource/deleteById?id=${id}`;
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'delete',
      contentType: 'application/json',

      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};
