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

// ─── Channels ─────────────────────────────────────────────────────────────────
export const channelApi = {
  getList: (params) => request.get('/crm/channels', { params }),
  getDetail: (id) => request.get(`/crm/channels/${id}`),
  create: (data) => request.post('/crm/channels', data),
  update: (id, data) => request.put(`/crm/channels/${id}`, data),
  delete: (id) => request.delete(`/crm/channels/${id}`)
}

// ─── Leads ────────────────────────────────────────────────────────────────────
export const leadApi = {
  getList: (params) => request.get('/crm/leads', { params }),
  getDetail: (id) => request.get(`/crm/leads/${id}`),
  create: (data) => request.post('/crm/leads', data),
  update: (id, data) => request.put(`/crm/leads/${id}`, data),
  delete: (id) => request.delete(`/crm/leads/${id}`),
  follow: (id, data) => request.post(`/crm/leads/${id}/follow`, data),
  assign: (id, data) => request.put(`/crm/leads/${id}/assign`, data)
}

// ─── Customers ────────────────────────────────────────────────────────────────
export const customerApi = {
  getList: (params) => request.get('/crm/customers', { params }),
  getDetail: (id) => request.get(`/crm/customers/${id}`),
  create: (data) => request.post('/crm/customers', data),
  update: (id, data) => request.put(`/crm/customers/${id}`, data),
  delete: (id) => request.delete(`/crm/customers/${id}`)
}

// ─── Contracts ────────────────────────────────────────────────────────────────
export const contractApi = {
  getList: (params) => request.get('/crm/contracts', { params }),
  getDetail: (id) => request.get(`/crm/contracts/${id}`),
  create: (data) => request.post('/crm/contracts', data),
  update: (id, data) => request.put(`/crm/contracts/${id}`, data),
  delete: (id) => request.delete(`/crm/contracts/${id}`),
  audit: (id, data) => request.put(`/crm/contracts/${id}/audit`, data)
}

// ─── Questionnaires ───────────────────────────────────────────────────────────
export const questionnaireApi = {
  getList: (params) => request.get('/crm/questionnaires', { params }),
  getDetail: (id) => request.get(`/crm/questionnaires/${id}`),
  create: (data) => request.post('/crm/questionnaires', data),
  update: (id, data) => request.put(`/crm/questionnaires/${id}`, data),
  delete: (id) => request.delete(`/crm/questionnaires/${id}`),
  submitAnswer: (data) => request.post('/crm/questionnaire-answers', data),
  getAnswers: (params) => request.get('/crm/questionnaire-answers', { params })
}

// ─── Complaints ───────────────────────────────────────────────────────────────
export const complaintApi = {
  getList: (params) => request.get('/crm/complaints', { params }),
  getDetail: (id) => request.get(`/crm/complaints/${id}`),
  create: (data) => request.post('/crm/complaints', data),
  update: (id, data) => request.put(`/crm/complaints/${id}`, data),
  delete: (id) => request.delete(`/crm/complaints/${id}`),
  handle: (id, data) => request.put(`/crm/complaints/${id}/handle`, data)
}
