import Axios from 'axios'

import {REQUEST_CONFIG, USER_ADMQ, USER_QUERY, USER_RESET_PWD, USER_AUTHORITY, USER_LOGIN, USER_LOGOUT, USER_INFO_GET,
  USER_PWD_UPDATE, USER_INFO_UPDATE, USER_PWD_CHECK} from '../../utils/RequestUrls'

var staticMethods = {
  // 获取全部用户
  getAllUserCollection: function () {
    return Axios.get(USER_ADMQ)
  },

  // 添加用户
  postAddUser: function (user) {
    return Axios.post(USER_ADMQ, user, REQUEST_CONFIG)
  },

  // 删除用户
  deleteUser: function (userKeyList) {
    return Axios.delete(USER_ADMQ, {
      data: userKeyList,
      headers: {'Content-Type': 'application/json', 'Encoding': 'utf-8'}
    })
  },

  // 修改用户
  putModifyUser: function (user) {
    return Axios.put(USER_ADMQ, user, REQUEST_CONFIG)
  },

  // 条件查询用户信息
  putConditionQueryUser: function (selectList) {
    return Axios.put(USER_QUERY, selectList, REQUEST_CONFIG)
  },

  // 重置用户密码
  putResetUserPassword: function (user) {
    return Axios.put(USER_RESET_PWD, user, REQUEST_CONFIG)
  },

  // 登录
  getLogin: function (arr) {
    return Axios.post(USER_LOGIN, arr, {headers: {'Content-Type': 'application/json'}})
    // return $.ajax({
    //   url:'./static/ipconfig.json',//url路径
    //   // type:'GET', //GET
    //   // async:false, //或false,是否异步
    //   // timeout:5000, //超时时间
    //   // dataType:'json', //返回的数据格式：
    //   success:function(data,textStatus,jqXHR){
    //     protocal = data.protocal;
    //   },
    //   error:function(xhr,textStatus){
    //     console.log("ipconfig配置失败！");
    //   }
    // })
  },

  // 注销
  postLogout: function () {
    return Axios.post(USER_LOGOUT, {}, {headers: {'Content-Type': 'application/json'}})
  },

  // 获取用户权限
  getAllUserAuthority: function () {
    return Axios.get(USER_AUTHORITY, {headers: {'Content-Type': 'application/json'}})
  },

  // 获取个人信息
  getUserInfo: function () {
    return Axios.get(USER_INFO_GET)
  },

  // 修改个人信息
  putModifyUserInfo: function (userInfo) {
    return Axios.put(USER_INFO_UPDATE, userInfo, REQUEST_CONFIG)
  },

  // 修改个人密码
  putModifyUserPwd: function (arr) {
    return Axios.post(USER_PWD_UPDATE, arr, REQUEST_CONFIG)
  },

  // 用户密码认证
  getCheckPwd: function (pwd) {
    return Axios.put(USER_PWD_CHECK, pwd, REQUEST_CONFIG)
  }
}

function UserAPI (websocketService = null) {
  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(UserAPI, staticMethods)
export default UserAPI
