import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CustomerInfoVO, CustomerInfoForm, CustomerInfoQuery } from '@/api/customer/customerFile/customerInfo/types';

/**
 * 查询客户信息列表
 * @param query
 * @returns {*}
 */

export const listCustomerInfo = (query?: CustomerInfoQuery): AxiosPromise<CustomerInfoVO[]> => {
  return request({
    url: '/customer/customerInfo/list',
    method: 'get',
    params: query
  });
};

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

/**
 * 新增客户信息
 * @param data
 */
export const addCustomerInfo = (data: CustomerInfoForm) => {
  return request({
    url: '/customer/customerInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改客户信息
 * @param data
 */
export const updateCustomerInfo = (data: CustomerInfoForm) => {
  return request({
    url: '/customer/customerInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除客户信息
 * @param id
 */
export const delCustomerInfo = (id: string | number | Array<string | number>) => {
  return request({
    url: '/customer/customerInfo/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param id 客户id
 * @param status 状态
 */
export function changeStatus(id: string, status: string) {
  const data = {
    id,
    status
  };
  return request({
    url: '/customer/customerInfo/changeStatus',
    method: 'put',
    data: data
  });
}

/**
 * 修改临时额度
 * @param customerIds 客户id
 * @param creditAmount 额度
 */
export function updateCreditAmount(customerIds: number[], temporaryQuota: number) {
  const data = {
    customerIds,
    temporaryQuota
  };
  return request({
    url: '/customer/customerInfo/updateCreditAmount',
    method: 'put',
    data: data
  });
}

/**
 * 修改临时额度
 * @param customerIds 客户id
 * @param tagIds 标签id
 */
export function setCustomerInfoTag(customerIds: number[], tagIds: number[]) {
  const data = {
    customerIds,
    tagIds
  };
  return request({
    url: '/customer/customerInfo/setCustomerInfoTag',
    method: 'put',
    data: data
  });
}

export const listContractList = (query?: CustomerInfoQuery): AxiosPromise<CustomerInfoVO[]> => {
  return request({
    url: '/customer/customerInfo/contractList',
    method: 'get',
    params: query
  });
};

/**
 * 根据名称模糊查询客户信息
 * @param customerName
 */
export const getListBycustomerName = (customerName: string): AxiosPromise<CustomerInfoVO[]> => {
  return request({
    url: '/customer/customerInfo/selectByCustomerName/' + customerName,
    method: 'get'
  });
};
