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

export namespace RoleApi {
  export interface Role {
    [key: string]: any;
    name: string;
    dataScope: string;
    enabled: boolean;
    deptId: string;
    remark?: string;
    createBy: string;
    menuIds: [];
    createTime: string;
    createId: string;
    // authorities: (number | undefined)[];
    id: string;
  }

  export interface RoleListParams {
    page: number;
    size: number;
    sort: string;
    name?: string;
    enabled?: boolean;
    deptId?: string;
  }

  export interface RoleListRecord extends Role {
    name: string;
  }
}

// 查询所有的角色列表、
export function queryRoleList(data: RoleApi.RoleListParams) {
  // return axios.get('/rest/role',data);
  return requestClient.get<Array<RoleApi.Role>>('/rest/role', { params: data });
}

// 切换启用状态
export function enabledRole(id: string) {
  return requestClient.patch(`/rest/role/${id}/toggle`);
}

// 删除
export function removeRole(id: string) {
  return requestClient.delete(`/rest/role/${id}`);
}

// 添加
export function createRole(data: RoleApi.Role) {
  return requestClient.post(`/rest/role`, data);
}

// 更新
export function updateRole(id: any, data: RoleApi.Role) {
  return requestClient.patch(`/rest/role/${id}`, data);
}

// 获取详情
export function roleDetail(id: string) {
  return requestClient.get<RoleApi.Role>(`/rest/role/${id}`);
}

export const queryMenuList = (data: string) => {
  return requestClient.get('/rest/menu/tree', {
    params: {
      name: data,
    },
  });
};

// export function queryRoles(params?: ListParams<Partial<Role>>) {
//   return queryList<Role>(`/rest/role/query`, params);
// }
