import { get, post, put, del } from './request'
import type { Customer, CustomerStatus, PageResult } from '../types'

export interface CustomerParams {
  customerName: string
  contactName?: string
  phone?: string
  province?: string
  city?: string
  district?: string
  street?: string
  detailAddress?: string
  latitude?: string
  longitude?: string
  status?: CustomerStatus
  remark?: string
}

export function getCustomerList(pageNum = 1, pageSize = 10, keyword?: string) {
  return get<PageResult<Customer>>('/customer/list', { pageNum, pageSize, keyword })
}

export function getCustomerDetail(id: number | string) {
  return get<Customer>(`/customer/${id}`)
}

export function createCustomer(data: CustomerParams) {
  return post<boolean>('/customer', data)
}

export function updateCustomer(data: CustomerParams & { id: number | string }) {
  return put<boolean>('/customer', data)
}

export function deleteCustomer(id: number | string) {
  return del<boolean>(`/customer/${id}`)
}
