import api from './request'

// 支付相关API
export const getPayments = (params) => {
  return api.get('/payments', { params })
}

export const getPaymentById = (id) => {
  return api.get(`/payments/${id}`)
}

export const createPayment = (paymentData) => {
  return api.post('/payments/create', paymentData)
}

export const createTestPayment = (paymentData) => {
  return api.post('/payments/create-test', paymentData)
}

export const updatePaymentStatus = (id, status) => {
  return api.put(`/payments/${id}/status`, { status })
}

export const confirmPaymentSuccess = (id, externalTransactionId) => {
  return api.post(`/payments/${id}/success`, {
    externalTransactionId
  })
}

export const confirmPaymentFailure = (id, failureReason) => {
  return api.post(`/payments/${id}/failure`, {
    failureReason
  })
}

// 测试支付完成API
export const testPaymentComplete = (id) => {
  return api.post(`/payments/${id}/test-complete`)
}

// 支付宝支付API
export const createAlipayPayment = (paymentData) => {
  return api.post(`/payments/alipay/create`, paymentData)
}

export const handleAlipayCallback = (params) => {
  return api.post('/payments/alipay/callback', params)
}

// PayPal支付API
export const createPayPalPayment = (paymentData) => {
  return api.post(`/payments/paypal/create`, paymentData)
}

export const handlePayPalCallback = (params) => {
  return api.post('/payment/paypal/callback', params)
}

// 支付统计API
export const getPaymentStats = () => {
  return api.get('/payments/stats')
}
