import request from '@/utils/request.js'

// ─── Finance Categories ──────────────────────────────────────────────────────
export const financeCategoryApi = {
  getList: (params) => request.get('/finance/categories', { params }),
  getDetail: (id) => request.get(`/finance/categories/${id}`),
  create: (data) => request.post('/finance/categories', data),
  update: (id, data) => request.put(`/finance/categories/${id}`, data),
  delete: (id) => request.delete(`/finance/categories/${id}`)
}

// ─── Finance Records ─────────────────────────────────────────────────────────
export const financeRecordApi = {
  getList: (params) => request.get('/finance/records', { params }),
  getDetail: (id) => request.get(`/finance/records/${id}`),
  create: (data) => request.post('/finance/records', data),
  update: (id, data) => request.put(`/finance/records/${id}`, data),
  delete: (id) => request.delete(`/finance/records/${id}`),
  audit: (id, data) => request.put(`/finance/records/${id}/audit`, data)
}

// ─── Customer Accounts ───────────────────────────────────────────────────────
export const customerAccountApi = {
  getList: (params) => request.get('/finance/accounts', { params }),
  recharge: (data) => request.post('/finance/accounts/recharge', data)
}

// ─── Account Transactions ────────────────────────────────────────────────────
export const accountTransactionApi = {
  getList: (params) => request.get('/finance/transactions', { params })
}

// ─── Prepaid Cards ───────────────────────────────────────────────────────────
export const prepaidCardApi = {
  getList: (params) => request.get('/finance/prepaid-cards', { params }),
  getDetail: (id) => request.get(`/finance/prepaid-cards/${id}`),
  create: (data) => request.post('/finance/prepaid-cards', data),
  update: (id, data) => request.put(`/finance/prepaid-cards/${id}`, data),
  delete: (id) => request.delete(`/finance/prepaid-cards/${id}`)
}

// ─── Invoices ────────────────────────────────────────────────────────────────
export const invoiceApi = {
  getList: (params) => request.get('/finance/invoices', { params }),
  getDetail: (id) => request.get(`/finance/invoices/${id}`),
  create: (data) => request.post('/finance/invoices', data),
  update: (id, data) => request.put(`/finance/invoices/${id}`, data),
  delete: (id) => request.delete(`/finance/invoices/${id}`),
  issue: (id) => request.put(`/finance/invoices/${id}/issue`)
}

// ─── Payment Records ──────────────────────────────────────────────────────────
export const paymentApi = {
  getList: (params) => request.get('/finance/records', { params: { type: 'payment', ...params } }),
  create: (data) => request.post('/finance/records', data),
  audit: (id, data) => request.put(`/finance/records/${id}/audit`, data) // was: confirm → audit
}
