function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { EnvironmentEnum } from "../../../types";
import { TrackerBusSubscriber } from "./ability/tracker";
import { ServiceProvider } from '..';
import { SecurityBusSubscriber } from "./ability/security";
import { DataBusSubscriber } from "./ability/globalData";
import { RequestBusSubscriber } from "./ability/request";
import { BusManager } from "./busManager";

/**
 * @author 谦彧 <zhangmian.zm@alipay.com>
 * @date 2024/9/17
 */
export var ApiBusManagerService = /*#__PURE__*/function () {
  function ApiBusManagerService() {
    _classCallCheck(this, ApiBusManagerService);
    _defineProperty(this, "logger", void 0);
    _defineProperty(this, "instanceId", void 0);
    _defineProperty(this, "busManager", void 0);
  }
  _createClass(ApiBusManagerService, [{
    key: "init",
    value: function init(initOptions, instanceId) {
      var _this = this;
      this.instanceId = instanceId;
      this.logger = ServiceProvider.getInstance(this.instanceId).getService('Log');
      this.busManager = new BusManager(this.instanceId);
      this.busManager.debugTrace((initOptions === null || initOptions === void 0 ? void 0 : initOptions.environment) !== EnvironmentEnum.prod);
      this.busManager.clear();
      // addInterceptor
      this.busManager.addInterceptor({
        onPublishException: function onPublishException(message, e) {
          _this.logger.logError({
            title: 'onBusPublishException'
          }, _objectSpread(_objectSpread({}, message), {}, {
            errorMessage: JSON.stringify(e)
          }));
        }
      });
      // subscribe basic ability TODO
      // this.busManager.subscribe(
      //   new SDKCallbackBusSubscriber((state: { code: string; message?: string; result?: EventCallbackResult }) => {
      //     const eventCenter = ServiceProvider.getInstance(this.instanceId).getService<EventCenter>('EventCenter');
      //     eventCenter.emit(EVENT.eventCallback.name, state);
      //   }),
      // );
      this.busManager.subscribe(new SecurityBusSubscriber(this.instanceId));
      this.busManager.subscribe(new TrackerBusSubscriber(this.instanceId));
      this.busManager.subscribe(new DataBusSubscriber(this.instanceId));
      this.busManager.subscribe(new RequestBusSubscriber(this.instanceId));
    }
  }, {
    key: "subscribe",
    value: function subscribe(subscriber) {
      this.busManager.subscribe(subscriber);
    }
  }, {
    key: "unsubscribe",
    value: function unsubscribe(subscriber) {
      this.busManager.unsubscribe(subscriber);
    }
  }, {
    key: "isSubscribed",
    value: function isSubscribed(actionName) {
      return this.busManager.isSubscribed(actionName);
    }
  }, {
    key: "publish",
    value: function publish(message, callback) {
      this.busManager.publish(message, callback);
    }
  }, {
    key: "update",
    value: function update() {}
  }, {
    key: "destroy",
    value: function destroy() {}
  }]);
  return ApiBusManagerService;
}();