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

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

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

interface RolePartialEntity extends Partial<Omit<RoleGroupEntity, 'title'>> {
  title?: string;
}

interface RoleQueryParams extends PageConfig, RolePartialEntity {}

/**
 * 角色信息_列表
 */
export async function getRoleListApi(params: RoleQueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=88', {
    ...params,
  });
}

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

/**
 * 角色信息_新增
 */
export async function addRoleApi(data: RoleGroupEntity) {
  return requestClient.post<any>('/api/add?pagevalue=90', { ...data });
}

/**
 * 角色信息_编辑
 */
export async function editRoleApi(data: RoleGroupEntity) {
  return requestClient.post<any>('/api/up?pagevalue=91', { ...data });
}

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