import { config, networkUtils } from '../../utils';

const { api } = config;
const { sys } = api;
const { powers } = sys;
const { iam } = sys;

const { findUsers, userOf, rolesChanged, user, updatePassword } = iam;

// findUsers: '/edp/iam/users',            // 用户查询
// userOf: '/edp/iam/users/{id}',          // 用户明细
// rolesChanged: '/edp/iam/roles/changed', // (仅用于运营方用户)系统角色或流程角色改变是调用，用来校准两者的依赖关系
// createUser: '/edp/iam/users',           // (仅用于运营方用户)新建用户
// updateUser: '/edp/iam/users/{id}',      // (仅用于运营方用户)修改用户
// enableUser: '/edp/iam/users/{id}/o',    // (仅用于运营方用户)启用账户
// disableUser: '/edp/iam/users/{id}/x',   // (仅用于运营方用户)禁用账户
// updatePassword: '/edp/iam/users/{id}/p?p={p}',  // (仅用于运营方用户)更新密码

export async function queryEntUsers(params) {
  return networkUtils.request({
    url: findUsers,
    method: 'get',
    data: { ...params, suppMode: false },
  });
}

export async function querySuppUsers(params) {
  return networkUtils.request({
    url: findUsers,
    method: 'get',
    data: { ...params, suppMode: true },
  });
}


export async function getSingle(id) {
  return networkUtils.request({
    url: userOf.replace('{id}', id),
    method: 'get',
  });
}

export async function create(params) {
  return networkUtils.request({
    url: user,
    method: 'post',
    data: params,
  });
}

export async function update({ id, ...params, }) {
  return networkUtils.request({
    url: `${user}/${id}`,
    method: 'post',
    data: params,
  });
}

export async function doUpdatePassword({ id, p }) {
  return networkUtils.request({
    url: `${updatePassword}/${id}/p?p=${p}`,
    method: 'post',
  });
}


export async function disable(id) {
  return networkUtils.request({
    url: `${user}/${id}/x`,
    method: 'post',
  });
}

export async function enable(id) {
  return networkUtils.request({
    url: `${user}/${id}/o`,
    method: 'post',
  });
}

export async function checkRoles(params) {
  return networkUtils.request({
    url: rolesChanged,
    method: 'get',
    data: params,
  });
}

export async function regQuery() {
  return networkUtils.request({
    url: api.common.suggest.regions,
    method: 'get',
  });
}


export async function itemQuery() {
  return networkUtils.request({
    url: api.common.suggest.udcItem,
    method: 'get',
    data: { domainCode: 'SUPP', udcCode: 'GYSYLSX' },
  });
}

export async function getPower(id) {
  return networkUtils.request({
    url: `${powers}/user/${id}`,
    method: 'get',
  });
}

export async function updatePower(params) {
  return networkUtils.request({
    url: `${powers}/save`,
    method: 'post',
    data: params,
  });
}
