import { params } from 'kit_utils';

export const API = {
  GET_CONFIG: '/CityInterface/rest/services.svc/GetConfig',
  GENERATE_TOKEN: '/cityinterface/rest/services.svc/generatetoken',
  GENERATE_IOT_TOKEN: 'cityinterface/rest/services.svc/generateGCKToken',
  GENERATE_QRCODE: 'cityinterface/rest/services.svc/generatetokenByqrcode',
  GENERATE_TOKEN_CHANGE: '/cityinterface/rest/services.svc/generatetokenquick',
  GET_WEB_SITE_CONFIG: '/CityInterface/rest/services.svc/GetWebSiteConfig',
  GET_USER_INFO: '/CityInterface/rest/services.svc/getUserInfo',
  GET_OA: '/CityInterface/rest/services/OA.svc/getLoginInfo',
  GET_LOGS: '/CityInterface/rest/services/portal.svc/OMMonitor/SaveLoginInfo',
  GET_CITY: 'https://pv.sohu.com/cityjson?ie=utf-8',
  GET_ALL_GROUPS_INFO_FORUSER:
    'CityInterface/rest/Services/Portal.svc/AuthorityManage/GetAllGroupsInfoForUser',
  GET_WEATHER: '/CityInterface/rest/services/CountyProduct.svc/GetWeather',
  SEND_MESSAGE_CODE: 'CityInterface/rest/services/portal.svc/SendMessVerificationCode',
  CHANGE_PASSWORD: 'cityinterface/rest/services.svc/changepassword',
  IOT_CHANGE_PASSWORD: 'CityInterface/rest/services/OMS.svc/U_UpdatePasswordQuickGCK',
  FILE_DOWNLOAD: '"/cityinterface/rest/services/filedownload.svc/download'
};
export default vm => {
  vm.getConfig = (
    data = { client: params.getParams('client') || 'city', ts: Date.now() },
    config = {},
  ) => vm.get(API.GET_CONFIG, data, config).then(res => Promise.resolve(res));

  vm.generateToken = (data = {}, config = {}) =>
    vm.get(window.globalConfig.loginTemplate === 'Dark - IOTMultiLogin.html' ? API.GENERATE_IOT_TOKEN: API.GENERATE_TOKEN, data, config).then(res => Promise.resolve(res));
  vm.generatetokenByqrcode = (data = {}, config = {}) => 
    vm.get(API.GENERATE_QRCODE, data, config).then(res => Promise.resolve(res));
  vm.getWebSiteConfig = (data = {}, config = {}) =>
    vm
      .get(API.GET_WEB_SITE_CONFIG, data, config)
      .then(res => Promise.resolve(res));

  vm.getUserInfo = (data = {}, config = {}) =>
    vm.get(API.GET_USER_INFO, data, config).then(res => Promise.resolve(res));

  vm.getOA = (data = {}) =>
    vm.get(API.GET_OA, data).then(res => Promise.resolve(res));

  vm.writeLogs = (data = {}, config = {}) =>
    vm.post(API.GET_LOGS, data, config).then(res => Promise.resolve(res));

  vm.getCity = () => vm.get(API.GET_CITY).then(res => Promise.resolve(res));

  vm.generateTokenQuick = (data = {}) =>
    vm.get(API.GENERATE_TOKEN_CHANGE, data).then(res => Promise.resolve(res));

  vm.getAllGroupsInfoForUser = (data = {}, config) =>
    vm
      .get(API.GET_ALL_GROUPS_INFO_FORUSER, data, config)
      .then(res => Promise.resolve(res));

  vm.getWeather = (data = {}, config) =>
    vm.get(API.GET_WEATHER, data, config).then(res => Promise.resolve(res));
  
  vm.sendMessVerificationCode  = (data = {}, config ={}) => vm.get(API.SEND_MESSAGE_CODE, data, config).then(res => Promise.resolve(res));

  vm.changePassword = (data = {}, config = {}) => vm.get(window.globalConfig.loginTemplate === 'Dark - IOTMultiLogin.html' ? API.IOT_CHANGE_PASSWORD: API.CHANGE_PASSWORD, data, config).then(res => Promise.resolve(res));
};
