import HelperUtil from '../../../utils/HelperUtil'
import {CDP_KEY} from "../../../utils/constantCollection";
import CDPAPI from "../../../api/restApis/BusinessAPI/CDPAPI";

// 静态方法
let staticMethods = {
  // 获取所有CDP业务
  getAllCDPCollection: function(){
    return CDPAPI.getCDPCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue,CDP_KEY);
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 添加CDP业务
  addCDP: function (cdpObj) {
    return CDPAPI.postAddCDP(cdpObj).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 删除CDP业务
  deleteCDP: function (cdpKeyList) {
    return CDPAPI.deleteDeleteCDP(cdpKeyList).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },
};

function CDPService (websocketService = null) {

  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(CDPService, staticMethods);
export default CDPService
