import { defHttp } from '/@/utils/http/axios';
import { setParams } from '/@/utils/index';

enum Api {
  sysPortalQueryPage = '/sys/portal/query/page',
  sysPortalDetail = '/sys/portal/detail',
  sysPortalAdd = '/sys/portal/add',
  sysPortalEdit = '/sys/portal/edit',
  sysPortalRemove = '/sys/portal/removeByIds',
  sysPortalAssign = '/sys/portal/assign',
  sysPortalQueryMenuTree = '/sys/portal/menu/list',
  userPortalList = '/user/listPortal',
}

/**
 *
 * @author fan
 * @date  2023/04/17 13:56
 * @description: 根据条件查询门户列表,权限 - sys:portal:query
 * @method: POST
 * @param:
 *       {String}  code  like   门户编码
 *       {String}  name     门户名称
 *       {String}  type     门户类型
 *       {String}  remark     备注
 *       {Integer}  sort     排序
 *       {String}  tenantId     租户id
 * @return:
 *       {String}  code  门户编码
 *       {String}  name  门户名称
 *       {String}  indexMenuId  门户首页菜单id
 *       {String}  type  门户类型
 *       {String}  remark  备注
 *       {Integer}  sort  排序
 */

export const sysPortalQueryPage = (params?: object) => {
  return defHttp.post({ url: Api.sysPortalQueryPage, params: setParams(params) });
};
/**
 *
 * @author fan
 * @date  2023/04/17 13:56
 * @description: 根据id查询门户详细信息,权限 - sys:portal:query
 * @method: GET
 * @param:  id 门户主键id
 * @return:
 *       {String}  code  门户编码
 *       {String}  name  门户名称
 *       {String}  indexMenuId  门户首页菜单id
 *       {String}  type  门户类型
 *       {String}  remark  备注
 *       {Integer}  sort  排序
 */
export const sysPortalDetail = (id: string) => {
  return defHttp.get({ url: Api.sysPortalDetail + '/' + id });
};

/**
 *
 * @author fan
 * @date  2023/04/17 13:56
 * @description: 添加门户,权限 - sys:portal:add
 * @method: POST
 * @param:
 *       {String}  code  门户编码
 *       {String}  name  门户名称
 *       {String}  indexMenuId  门户首页菜单id
 *       {String}  type  门户类型
 *       {String}  remark  备注
 *       {Integer}  sort  排序
 * @return:
 *       0 添加失败
 *       1 添加成功
 */
export const sysPortalAdd = (params?: object) => {
  return defHttp.post({ url: Api.sysPortalAdd, params: params });
};

/**
 *
 * @author fan
 * @date  2023/04/17 13:56
 * @description: 通过主键id编辑门户,权限 - sys:portal:edit
 * @method: POST
 * @param:
 *       {String}  code  门户编码
 *       {String}  name  门户名称
 *       {String}  indexMenuId  门户首页菜单id
 *       {String}  type  门户类型
 *       {String}  remark  备注
 *       {Integer}  sort  排序
 * @return:
 *       0 编辑失败
 *       1 编辑成功
 */
export const sysPortalEdit = (params?: object) => {
  return defHttp.post({ url: Api.sysPortalEdit, params: params });
};

/**
 * @description: 删除,权限 - sys:portal:remove
 * @method: POST
 */
export const sysPortalRemove = (params: Array<string | number>) => {
  return defHttp.post({ url: Api.sysPortalRemove, params: params });
};
/**
 * @description: 分配租户套餐,权限 - sys:tenantPackage:assign
 * @method: POST
 */
export const sysPortalAssign = (params?: object) => {
  return defHttp.post({ url: Api.sysPortalAssign, params: params });
};

/**
 * @description: 查询角色信息列表,权限 - sys:role:query
 * @method: POST
 */
export const sysPortalQueryMenuTree = id => {
  return defHttp.get({ url: Api.sysPortalQueryMenuTree + '/' + id });
};

/**
 * @description: 获取登录用户的门户列表
 * @method: GET
 */
export const getUserPortalList = () => {
  return defHttp.get({ url: Api.userPortalList });
};
