import { apiClient as client } from './client'

export function fetchRegistrations() {
  return client.get('/registrations').then(res => res.data)
}

export function fetchRegistration(id) {
  return client.get(`/registrations/${id}`).then(res => res.data)
}

export function createRegistration(payload) {
  return client.post('/registrations', payload).then(res => res.data)
}

export function updateRegistration(id, payload) {
  return client.put(`/registrations/${id}`, payload).then(res => res.data)
}

export function deleteRegistration(id) {
  return client.delete(`/registrations/${id}`).then(res => res.data)
}

export function sendSmsToUserPhone(id) {
  return client.get(`/registrations/sendSms/${id}`).then(res => res.data)
}

export function searchRegistrations(params = {}) {
  return client
    .get('/registrations/search', {
      params: {
        customerName: params.customerName,
        contact: params.contact,
        serviceType: params.serviceType,
        powerType: params.powerType,
        status: params.status,
        urlPath: params.urlPath
      }
    })
    .then(res => res.data)
}

export function searchByPhone(phoneNumber) {
  return searchRegistrations({ contact: phoneNumber, status: '已登记' })
}


export function serchUrlPath(urlPath) {
  return client.get(`/registrations/getPdfPath/${urlPath}`).then(res => res.data)
}