import { axios } from '@/utils/request'
import { stringify } from 'qs'

/**
 * page func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function getPurchaseOrderPage (parameter) {
  return axios({
    url: '/purchase/purchase-orders/page?' + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * add func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function addPurchaseOrder (parameter) {
  return axios({
    url: '/purchase/purchase-orders',
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * update func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function updatePurchaseOrder (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id,
    method: 'PUT',
    data: parameter
  })
}

/**
 * get func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function getOrderSuppliers (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id + '/suppliers',
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * finish func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function finish (id) {
  return axios({
    url: '/purchase/purchase-orders/' + id + '/finish',
    method: 'PUT'
  })
}

/**
 * update func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function confirmUpdateQuantityForInStore (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id + '/quantity/error',
    method: 'PUT',
    data: parameter
  })
}

/**
 * update func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function enquiryPurchaseOrder (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id + '/enquiry',
    method: 'PUT',
    data: parameter
  })
}

/**
 * update func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function enquiryPurchaseOrderConfirm (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id + '/enquiry-confirm',
    method: 'PUT',
    data: parameter
  })
}

/**
 * update func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function purchaseOrderMoneyConfirm (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id + '/money-confirm',
    method: 'PUT',
    data: parameter
  })
}

/**
 * update func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function updatePurchaseOrderInfo (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id + '/info',
    method: 'PUT',
    data: parameter
  })
}

/**
 * fetch single func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function fetchPurchaseOrder (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * query list func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function queryPurchaseOrder (parameter) {
  return axios({
    url: '/purchase/purchase-orders?' + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * delete batch func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function deletePurchaseOrders (parameter) {
  return axios({
    url: '/purchase/purchase-orders',
    method: 'DELETE',
    data: parameter
  })
}

/**
 * delete single func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function deletePurchaseOrder (parameter) {
  return axios({
    url: '/purchase/purchase-orders/' + parameter.id,
    method: 'DELETE',
    data: parameter
  })
}

/**
 * export file
 * parameter: { }
 * @param parameter :
 * @returns {*}
 */
export function exportPurchaseOrder (parameter) {
  return axios({
    url: '/purchase/purchase-orders/export?' + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    responseType: 'blob'
  })
}
