import type { CustomerEntity, PageConfig } from '@vben/types';

import { parseQueryValues } from '@vben/utils';

import { requestClient } from '#/api/request';

interface CustomerPartialEntity
  extends Partial<Omit<CustomerEntity, 'usersname' | 'usersphone'>> {
  usersphone?: string;
  usersname?: string;
}

interface CustomerQueryParams extends CustomerPartialEntity, PageConfig {
  [key: `${string}.value`]: boolean | number | string;
}

/**
 * 客户信息_列表
 */
export async function getCustomerListApi(params: CustomerQueryParams) {
  const queryParams = params;
  if (params.usersnature) {
    queryParams['usersnature.value'] = params.usersnature;
  }
  return requestClient.post<any>('/api/query/list?pagevalue=17', {
    ...params,
  });
}

/**
 * 客户信息_详情
 */
export async function getCustomerDetailApi(data: { usersid: string }) {
  return requestClient.post<any>(
    '/api/query/view?pagevalue=19',
    {
      ...parseQueryValues(data),
    },
    { formatData: true }, // 格式化返回数据
  );
}

/**
 * 客户信息_新增
 */
export async function addCustomerApi(data: CustomerEntity) {
  return requestClient.post<any>('/api/add?pagevalue=20', { ...data });
}

/**
 * 客户信息_编辑
 */
export async function editCustomerApi(data: CustomerEntity) {
  return requestClient.post<any>('/api/up?pagevalue=21', { ...data });
}

/**
 * 客户信息_删除
 */
export async function deleteCustomerApi(data: { 'usersid.value': string }) {
  return requestClient.post<any>('/api/del?pagevalue=22', { ...data });
}

/**
 * 客户_生产厂家_列表
 */
export async function getCustomerScqyListApi(data: any) {
  return requestClient.post<any>('/api/query/list?pagevalue=123', { ...data });
}
