import { params } from 'kit_utils';

const API = {
  GET_CONFIG: '/CityInterface/rest/services.svc/GetConfig',
  GENERATE_TOKEN: '/cityinterface/rest/services.svc/generatetoken',
  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',
};
export default vm => {
  vm.getConfig = (
    data = { client: params.getParams('client') || 'city', ts: Date.now() },
  ) => vm.get(API.GET_CONFIG, data).then(res => Promise.resolve(res));

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

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

  vm.getUserInfo = (data = {}) =>
    vm.get(API.GET_USER_INFO, data).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 = {}) =>
    vm.get(API.GET_WEATHER, data).then(res => Promise.resolve(res));
};
