import request from '@/utils/request'

// 查询供应商列表
export function listSupplier(query) {
  return request({
    url: '/resources/suppliers/list',
    method: 'get',
    params: query
  })
}

// 查询供应商详细
export function getSupplier(id) {
  return request({
    url: '/resources/suppliers/' + id,
    method: 'get'
  })
}

// 新增供应商
export function addSupplier(data) {
  return request({
    url: '/resources/suppliers',
    method: 'post',
    data: data
  })
}

// 修改供应商
export function updateSupplier(data) {
  return request({
    url: '/resources/suppliers',
    method: 'put',
    data: data
  })
}

// 删除供应商
export function delSupplier(id) {
  return request({
    url: '/resources/suppliers/' + id,
    method: 'delete'
  })
}

// 启用供应商
export function activateSupplier(id) {
  return request({
    url: '/resources/suppliers/' + id + '/activate',
    method: 'post'
  })
}

// 停用供应商
export function deactivateSupplier(id) {
  return request({
    url: '/resources/suppliers/' + id + '/deactivate',
    method: 'post'
  })
}

// 加入黑名单
export function blacklistSupplier(id) {
  return request({
    url: '/resources/suppliers/' + id + '/blacklist',
    method: 'post'
  })
}

// 评分供应商
export function rateSupplier(id, rating) {
  return request({
    url: '/resources/suppliers/' + id + '/rate',
    method: 'post',
    data: { rating }
  })
}

// 查询供应商资质列表
export function listSupplierLicense(supplierId, query) {
  return request({
    url: '/resources/suppliers/' + supplierId + '/licenses',
    method: 'get',
    params: query
  })
}

// 查询供应商资质详细
export function getSupplierLicense(supplierId, licenseId) {
  return request({
    url: '/resources/suppliers/licenses/' + licenseId,
    method: 'get'
  })
}

// 新增供应商资质
export function addSupplierLicense(supplierId, data) {
  return request({
    url: '/resources/suppliers/' + supplierId + '/licenses',
    method: 'post',
    data: data
  })
}

// 修改供应商资质
export function updateSupplierLicense(supplierId, licenseId, data) {
  return request({
    url: '/resources/suppliers/' + supplierId + '/licenses/' + licenseId,
    method: 'put',
    data: data
  })
}

// 删除供应商资质
export function delSupplierLicense(supplierId, licenseId) {
  return request({
    url: '/resources/suppliers/' + supplierId + '/licenses/' + licenseId,
    method: 'delete'
  })
}