import request from '@/utils/request'

const api = {
  addressList: '/staff/addresses',
  addressAllList: '/staff/addresses/all',
  addressExpress: '/orders/{order}/express',
  addressCreate: '/staff/addresses',
  addressDetail: '/staff/addresses/{addressId}',
  updateAddress: '/staff/addresses/{addressId}',
  deleteAddress: '/staff/addresses/{addressId}',
  defaultAddress: '/staff/addresses/{addressId}/default'
}

/**
 * 获取地址列表
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getAddrList (parameter) {
  return request({
    url: api.addressList,
    method: 'get',
    params: parameter
  })
}

// 获取所有地址
export function getAllAddrList () {
  return request({
    url: api.addressAllList,
    method: 'get'
  })
}

// 指派邮寄地址
export function addressExpress (order, parameter) {
  return request({
    url: api.addressExpress.replace('{order}', order),
    method: 'post',
    params: parameter
  })
}

/**
 * 新增地址
 * @param parameter
 * @returns {AxiosPromise}
 */
export function createAddr (parameter) {
  return request({
    url: api.addressCreate,
    method: 'post',
    data: parameter
  })
}

/**
 * 获取地址详情
 * @param addressId
 * @returns {AxiosPromise}
 */
export function getAddr (addressId) {
  return request({
    url: api.addressDetail.replace('{addressId}', addressId),
    method: 'get'
  })
}

/**
 * 编辑地址
 * @param addressId
 */
export function updateAddr (addressId, parameter) {
  return request({
    url: api.updateAddress.replace('{addressId}', addressId),
    method: 'put',
    data: parameter
  })
}

/**
 * 删除地址
 * @param addressId
 */
export function deleteAddr (addressId) {
  return request({
    url: api.deleteAddress.replace('{addressId}', addressId),
    method: 'delete'
  })
}

/**
 * 默认地址
 * @param parameter
 * @returns {AxiosPromise}
 */
export function defaultAddress (addressId) {
  return request({
    url: api.defaultAddress.replace('{addressId}', addressId),
    method: 'post'
  })
}
