import { request } from '../request';

/** get role list */
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/smqjh-system/api/v1/roles/page',
    method: 'get',
    params
  });
}

/**
 * get all roles
 *
 * these roles are all enabled
 */
export function fetchGetAllRoles() {
  return request<Api.SystemManage.AllRole[]>({
    url: '/smqjh-system/api/v1/roles/options',
    method: 'get'
  });
}

/** get user list */
export function fetchGetUserList(params?: { keywords?: string; status?: number; deptId?: number }) {
  return request<Api.SystemManage.userList[]>({
    url: '/smqjh-system/api/v1/users/page',
    method: 'get',
    params
  });
}

/** get menu list */
export function fetchGetMenuList() {
  return request<Api.SystemManage.Menu[]>({
    // url: '/systemManage/getMenuList/v2',
    url: '/smqjh-system/api/v1/menus',
    method: 'get'
  });
}

/** get all pages */
export function fetchGetAllPages() {
  return request<string[]>({
    url: '/systemManage/getAllPages',
    method: 'get'
  });
}

/** get menu tree */
export function fetchGetMenuTree() {
  return request<Api.SystemManage.MenuTree[]>({
    url: '/smqjh-system/api/v1/menus/options',
    method: 'get'
  });
}

/**
 * 新增菜单
 * @param data
 * @returns
 */
export function fetchAddMenu(data: Api.SystemManage.AddMenu) {
  return request({
    url: '/smqjh-system/api/v1/menus',
    method: 'post',
    data
  });
}
/**
 * 编辑菜单
 * @param data
 * @returns
 */
export function fetchEditMenu(data: Api.SystemManage.AddMenu) {
  return request({
    url: `/smqjh-system/api/v1/menus/${data.id}`,
    method: 'put',
    data
  });
}

/**
 * 删除菜单
 * @param id
 * @returns
 */
export function fetchDelMenu(id: number) {
  return request({
    url: `/smqjh-system/api/v1/menus/${id}`,
    method: 'delete'
  });
}

/**
 * 获取角色菜单列表
 * @param roleId
 * @returns
 */
export function fetchGetRoleMenuList(roleId: number) {
  return request<Api.SystemManage.RoleMenuList>({
    url: `/sys/role/info/${roleId}`,
    method: 'get'
  });
}
/**
 * 新增角色菜单列表
 * @param data
 * @returns
 */
export function fetchAddRoleMenu(data: any) {
  return request({
    url: '/smqjh-system/api/v1/roles',
    method: 'post',
    data
  });
}
/**
 * 修改角色菜单列表
 * @param data
 * @returns
 */
export function fetchEditRoleMenu(data: any) {
  return request({
    url: `/smqjh-system/api/v1/roles/${data.id}`,
    method: 'put',
    data
  });
}
/**
 * 分配菜单权限给角色
 *
 * @param queryParams
 */
export function fetchUpdateRoleMenus(roleId: number, data: number[]) {
  return request({
    url: `/smqjh-system/api/v1/roles/${roleId}/menus`,
    method: 'put',
    data
  });
}
/**
 * 获取角色详情
 *
 * @param id
 */
export function fetchGetRoleForm(id: number) {
  return request({
    url: `/smqjh-system/api/v1/roles/${id}/form`,
    method: 'get'
  });
}
/**
 * 删除角色
 * @param roleId
 * @returns
 */

export function fetchDelRoleMenu(roleId: string) {
  return request({
    url: `/smqjh-system/api/v1/roles/${roleId}`,
    method: 'delete'
  });
}

/**
 *  获取所有角色
 * @returns
 */
export function fetchGetRoleAllList() {
  return request<Api.SystemManage.RoleList>({
    url: '/smqjh-system/api/v1/roles/options',
    method: 'get'
  });
}

/**
 * 新增用户
 * @param data
 * @returns
 */
export function fetchAddUser(data: Api.SystemManage.UserModel) {
  return request({
    url: '/smqjh-system/api/v1/users',
    method: 'post',
    data
  });
}
/**
 * 获取角色的菜单ID集合
 *
 * @param queryParams
 */
export function fetchGetRoleMenuIds(roleId: number) {
  return request({
    url: `/smqjh-system/api/v1/roles/${roleId}/menuIds`,
    method: 'get'
  });
}

/**
 * 修改用户
 * @param data
 * @returns
 */ export function fetchEditUser(data: Api.SystemManage.UserModel) {
  return request({
    url: `/smqjh-system/api/v1/users/${data.id}`,
    method: 'put',
    data
  });
}

/**
 * 用户详情
 * @param id
 * @returns
 */
export function fetchDetaileUser(id: string) {
  return request<Api.SystemManage.UserModel>({
    url: `/smqjh-system/api/v1/users/${id}/form`,
    method: 'get'
  });
}

/**
 * 删除用户
 * @param id
 * @returns
 */
export function fetchDeleteUser(id: string) {
  return request({
    url: `/smqjh-system/api/v1/users/${id}`,
    method: 'delete'
  });
}

/** 根据字典类型查询字典数据信息 */
export function fetchGetDictDataByType(dictType: string) {
  return request<Api.System.DictData[]>({
    url: `/smqjh-system/api/v1/dict/types/${dictType}/list`,
    method: 'get'
  });
}

/** 获取字典选择框列表 */
export function fetchGetDictTypeOption() {
  return request<Api.System.DictType[]>({
    url: '/smqjh-system/api/v1/dict/types/getDictTypeList',
    method: 'get'
  });
}

/** 新增字典类型 */
export function fetchCreateDictType(data: any) {
  return request<boolean>({
    url: '/smqjh-system/api/v1/dict/types',
    method: 'post',
    data
  });
}

/** 修改字典类型 */
export function fetchUpdateDictType(data: any) {
  return request<boolean>({
    url: `/smqjh-system/api/v1/dict/types/${data.id}`,
    method: 'put',
    data
  });
}

/** 批量删除字典类型 */
export function fetchBatchDeleteDictType(dictIds: number) {
  return request<boolean>({
    url: `/smqjh-system/api/v1/dict/types/${dictIds}`,
    method: 'delete'
  });
}

/** 获取字典数据列表 */
export function fetchGetDictDataList(params?: any) {
  return request<Api.System.DictDataList>({
    url: `/smqjh-system/api/v1/dict/page`,
    method: 'get',
    params
  });
}

/** 新增字典数据 */
export function fetchCreateDictData(data: any) {
  return request<boolean>({
    url: '/smqjh-system/api/v1/dict',
    method: 'post',
    data
  });
}

/** 修改字典数据 */
export function fetchUpdateDictData(data: any) {
  return request<boolean>({
    url: `/smqjh-system/api/v1/dict/${data.id}`,
    method: 'put',
    data
  });
}

/** 批量删除字典数据 */
export function fetchBatchDeleteDictData(dictCodes: CommonType.IdType[]) {
  return request<boolean>({
    url: `/smqjh-system/api/v1/dict/${dictCodes.join(',')}`,
    method: 'delete'
  });
}
