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

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

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

interface AccountPartialEntity
  extends Partial<Omit<AccountEntity, 'accountname'>> {
  accountname?: string;
}

interface AccountQueryParams extends AccountPartialEntity, PageConfig {}

/**
 * 账号信息_列表
 */
export async function getAccountListApi(params: AccountQueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=68', {
    ...params,
  });
}

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

/**
 * 客户_职员_视图列表
 */
export async function getAccountWorkerListApi(params: AccountQueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=122', {
    ...params,
  });
}

/**
 * 账号信息_新增
 */
export async function addAccountApi(data: AccountEntity) {
  return requestClient.post<any>('/api/add?pagevalue=70', { ...data });
}

/**
 * 账号信息_编辑
 */
export async function editAccountApi(data: AccountEntity) {
  return requestClient.post<any>('/api/up?pagevalue=71', {
    'accountid.value': data.accountid,
    ...data,
  });
}

/**
 * 账号信息_删除
 */
export async function deleteAccountApi(data: { 'accountid.value': string }) {
  return requestClient.post<any>('/api/del?pagevalue=72', { ...data });
}
