import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CustomerVO, CustomerForm, CustomerQuery } from '@/api/system/customer/types';

/**
 * 查询客户列表
 * @param query
 */
export const listCustomer = (query?: CustomerQuery): AxiosPromise<CustomerVO[]> => {
  return request({
    url: '/system/customer/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询客户详细
 * @param id
 */
export const getCustomer = (id: string | number): AxiosPromise<CustomerVO> => {
  return request({
    url: '/system/customer/' + id,
    method: 'get'
  });
};

/**
 * 新增客户
 * @param data
 */
export const addCustomer = (data: CustomerForm) => {
  return request({
    url: '/system/customer',
    method: 'post',
    data: data
  });
};

/**
 * 授权客户
 * @param id 客户ID
 * @param authClientFRowID ERP客户 RowID
 * @Author: Antigravity
 */
export const authCustomer = (id: string | number, authClientFRowID: string) => {
  return request({
    url: '/system/customer/auth',
    method: 'put',
    params: { id, authClientFRowID }
  });
};


/**
 * 导出客户列表
 * @param query
 */
export const exportCustomer = (query: CustomerQuery) => {
  return request({
    url: '/system/customer/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};
