import {http2} from "@/utils/request.js";

/**---------------------------------- */
/**优惠码/代金券管理 (统一接口) */

/**获取优惠码/代金券列表 */
export const getDiscountCodeList = (params) => {
  return http2.get('/api/v1/admin/code/discount/list', {params: params})
}

/**获取优惠码/代金券详情 */
export const getDiscountCodeDetail = (params) => {
  return http2.get('/api/v1/admin/code/discount/detail', {params: params})
}

/**创建优惠码/代金券 */
export const createDiscountCode = (data) => {
  return http2.post('/api/v1/admin/code/discount/create', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**更新优惠码/代金券 */
export const updateDiscountCode = (data) => {
  return http2.post('/api/v1/admin/code/discount/update', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**删除优惠码/代金券 */
export const deleteDiscountCode = (data) => {
  return http2.delete('/api/v1/admin/code/discount/delete?code_id=' + data.code_id)
}

/**---------------------------------- */
/**商品关联管理 */

/**获取优惠码/代金券商品列表 */
export const getDiscountGoodsList = (params) => {
  return http2.get('/api/v1/admin/code/discount/goods/list', {params: params})
}

/**新增优惠码/代金券商品关联 */
export const addDiscountGoods = (data) => {
  return http2.post('/api/v1/admin/code/discount/goods/add', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**修改优惠码/代金券商品关联 */
export const updateDiscountGoods = (data) => {
  return http2.post('/api/v1/admin/code/discount/goods/update', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**删除优惠码/代金券商品关联 */
export const deleteDiscountGoods = (data) => {
  return http2.delete('/api/v1/admin/code/discount/goods/delete', {
    data: data,
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**---------------------------------- */
/**用户关联管理 */

/**获取优惠码/代金券用户关联列表 */
export const getDiscountUsersList = (params) => {
  return http2.get('/api/v1/admin/code/discount/users/list', {params: params})
}

/**新增优惠码/代金券用户关联 */
export const addDiscountUsers = (data) => {
  return http2.post('/api/v1/admin/code/discount/users/add', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**修改优惠码/代金券用户关联 */
export const updateDiscountUsers = (data) => {
  return http2.post('/api/v1/admin/code/discount/users/update', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**删除优惠码/代金券用户关联 */
export const deleteDiscountUsers = (data) => {
  return http2.delete('/api/v1/admin/code/discount/users/delete', {
    data: data,
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**---------------------------------- */
/**用户代金券管理 */

/**获取用户优惠码/代金券列表 */
export const getUserVoucherList = (params) => {
  return http2.get('/api/v1/admin/code/discount/user/list', {params: params})
}

/**为用户添加代金券 */
export const addUserVoucher = (data) => {
  return http2.post('/api/v1/admin/code/discount/user/add_coupon', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**修改用户代金券 */
export const updateUserVoucher = (data) => {
  return http2.post('/api/v1/admin/code/discount/user/update_coupon', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**删除用户代金券 */
export const deleteUserVoucher = (data) => {
  return http2.delete('/api/v1/admin/code/discount/user/delete_coupon', {
    data: data,
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**获取用户优惠码/代金券使用记录 */
export const getUserVoucherHistory = (params) => {
  return http2.get('/api/v1/admin/code/discount/user/history', {params: params})
}

/**为用户分配代金券 */
export const allocateVoucher = (data) => {
  return http2.post('/api/v1/admin/code/discount/coupon/allocate', data,{
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/**查询代金券的拥有者列表 */
export const getVoucherHolderList = (params) => {
  return http2.get('/api/v1/admin/code/discount/coupon/holder_list', {params: params})
}

/**---------------------------------- */
/**兼容旧接口别名 */
export const getVoucherList = getDiscountCodeList
export const getVoucherDetail = getDiscountCodeDetail
export const createVoucher = createDiscountCode
export const updateVoucher = updateDiscountCode
export const deleteVoucher = deleteDiscountCode
