// import { get, post } from '@/services/index';
import qs from 'qs';
import { CITY_SERVICE, get, post, PUBLISH_SERVICE } from '@/services/index';

export const getUserTree = (selectOU, node) =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetOUTree`, {
    selectOU,
    node,
  });

// export const getOneOUUserListNew = OUID =>
//   get(`${CITY_SERVICE}/OMS.svc/U_GetOneOUUserListNew`, {
//     _version: 9999,
//     _dc: new Date().getTime(),
//     OUID,
//   });

export const getOneOUUserListNew = OUID =>
  get(`${PUBLISH_SERVICE}/UserCenter/GroupUserList`, {
    groupId: OUID,
  });

/**
 * 查询用户
 * @param {*} key
 */
// export const getUserByKey = key =>
//   get(`${CITY_SERVICE}/OMS.svc/U_GetUserByKey`, {
//     _version: 9999,
//     _dc: new Date().getTime(),
//     key,
//   });

export const GetUserByKeyNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetUserByKey`, params);

/**
 * 添加用户
 * @param {*} param0
 */
export const addUser = ({
  OUID,
  loginName,
  userName,
  password,
  phone,
  email,
}) =>
  get(`${PUBLISH_SERVICE}/UserCenter/AddUser`, {
    _version: 9999,
    _dc: Date.now(),
    OUID,
    loginName,
    userName,
    password,
    phone,
    email,
  });

export const addOrg = (orgID, OUName, description, comment) =>
  get(`${PUBLISH_SERVICE}/UserCenter/AddOU`, {
    pid: orgID,
    OUName,
    description,
    comment,
  });

export const editOrgInfo = (orgID, OUName, description, comment) =>
  get(`${PUBLISH_SERVICE}/UserCenter/EditOneOUInfo`, {
    ouid: orgID,
    ouName: OUName,
    description,
    comment,
  });

export const deleteOrg = orgID =>
  get(`${PUBLISH_SERVICE}/UserCenter/DeleteOU`, {
    OUID: orgID,
  });

export const getUserRelationList = userID =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetUserRelationList`, {
    userID: `${userID}`,
  });

export const addToOrg = (userID, orgID, newOrgID) =>
  get(`${PUBLISH_SERVICE}/UserCenter/JumpToAnotherOU`, {
    userID,
    oldOUID: orgID,
    newOUID: newOrgID,
  });
// 批量更改机构
export const addToOrgs = (userIDs, orgIDs, newOrgID) =>
  get(`${PUBLISH_SERVICE}/UserCenter/ModifyUserRole`, {
    userIds: userIDs,
    oldGroupIds: orgIDs,
    newGroupId: newOrgID,
  });

export const updateUserPassword = params =>
  post(`${PUBLISH_SERVICE}/UserCenter/UpdateUserPassword`, params);

//批量获取用户角色和机构
export const loadAllUserRole = params =>
  post(`${PUBLISH_SERVICE}/UserCenter/LoadAllUserRole`, params);

export const editUser = (userID, loginName, userName, phone, email) =>
  get(`${PUBLISH_SERVICE}/UserCenter/EditUser`, {
    userID,
    loginName,
    userName,
    phone,
    email,
  });

export const setUserState = (OUID, state) =>
  get(`${PUBLISH_SERVICE}/UserCenter/UserStateOU`, {
    OUID,
    state,
  });

// 批量删除用户
export const multiDeleteUsers = userIDs =>
  get(`${PUBLISH_SERVICE}/UserCenter/DeleteUsers`, {
    userIds: userIDs,
  });

export const setUserRelation = (userID, roleList = [], stationList) =>
  post(
    `${CITY_SERVICE}/OMS.svc/U_SetUserRelationList?_version=9999`,
    qs.stringify({
      userID,
      roleList: roleList.length ? `${roleList.join(',')},` : '',
      stationList: stationList.length ? `${stationList.join(',')},` : '',
      headList: '',
      mobileMapList: '',
      currentSolution: '熊猫智慧水务平台',
    }),
    {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    },
  );
export const SetUserRelationList = (userID, roleList = [], stationList) =>
  post(`${PUBLISH_SERVICE}/UserCenter/SetUserRelationList`,{
    userID,
    roleList: roleList.length ? `${roleList.join(',')},` : '',
    stationList: stationList.length ? `${stationList.join(',')},` : '',
    headList: '',
    mobileMapList: '',
    currentSolution: '熊猫智慧水务平台',
  });

export const setUserRelations = (userIDs, roleList, stationList) =>
  get(`${PUBLISH_SERVICE}/UserCenter/SetUserRoleMap`, {
    userIds: userIDs,
    roleIds: roleList || '',
    stationList: stationList || '',
  });

export const setOrgArea = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/SetOrgUserArea`, params);
export const getOrgArea = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetOrgUserArea`, params);
export const GetMapSetByGroupID = params =>
  get(`${PUBLISH_SERVICE}/Maplayer/GetMapSetByGroupID`, params);
export const GetOUTreeNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetOUTree`, params);

export const GetUserRelationListNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetUserRelationList`, params);

export const AddUserNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/AddUser`, params);

export const AddOUNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/AddOUNew`, params);

// export const EditOneOUInfoNew = params =>
// get(`${PUBLISH_SERVICE}/UserCenter/EditOneOUInfo`, params)

export const JumpToAnotherOUNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/JumpToAnotherOU`, params);

export const EditUserNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/EditUser`, params);

export const UserStateOUNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/UserStateOU`, params);

export const DeleteUserNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/DeleteUser`, params);

export const SetUserRelationListNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/SetUserRelationList`, params);

// export const DeleteOUNew = params =>
// get(`${PUBLISH_SERVICE}/UserCenter/DeleteOU`, params)
