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

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

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

interface DictPartialEntity extends Partial<Omit<DictEntity, 'title'>> {
  title?: string;
}

interface DictQueryParams extends DictPartialEntity, PageConfig {}

/**
 * 字典信息_列表
 */
export async function getDictListApi(params: DictQueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=73', {
    pageindex: params.pageindex,
    rows: params.rows,
    ...parseQueryValues({
      groupname: params.groupname,
    }),
  });
}

/**
 * 字典信息_详情
 */
export async function getDictDetailApi(data: { id: number }) {
  return requestClient.post<any>(
    '/api/query/view?pagevalue=74',
    {
      ...parseQueryValues(data),
    },
    { formatData: true },
  );
}

/**
 * 字典信息_新增
 */
export async function addDictApi(data: DictEntity) {
  return requestClient.post<any>('/api/add?pagevalue=75', { ...data });
}

/**
 * 字典信息_编辑
 */
export async function editDictApi(data: DictEntity) {
  return requestClient.post<any>('/api/up?pagevalue=76', { ...data });
}

/**
 * 字典信息_删除
 */
export async function deleteDictApi(data: { 'id.value': number }) {
  return requestClient.post<any>('/api/del?pagevalue=77', { ...data });
}
