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 _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 { ContainerService } from "./container/index";
import { LogService } from "./log";
import { EventCenter } from "./event-center";
import { RequesterService } from "./requester/requester";
import { SecurityService } from "./security";
import { ApiBusManagerService } from "./api-bus";
import { GlobalDataService } from "./global-data";

/**
 * @author 谦彧 <zhangmian.zm@alipay.com>
 * @date 2024/9/17
 */

export var ServiceProvider = /*#__PURE__*/function () {
  function ServiceProvider(instanceId) {
    _classCallCheck(this, ServiceProvider);
    _defineProperty(this, "instanceId", void 0);
    _defineProperty(this, "services", {
      Log: new LogService(),
      ApiBusManager: new ApiBusManagerService(),
      Requester: new RequesterService(),
      Container: new ContainerService(),
      Security: new SecurityService(),
      EventCenter: new EventCenter(),
      GlobalData: new GlobalDataService()
    });
    _defineProperty(this, "extendServices", {});
    this.instanceId = instanceId;
  }
  _createClass(ServiceProvider, [{
    key: "init",
    value: function init(initOptions, sdkMetaData) {
      this.services['Log'].init(initOptions, this.instanceId, sdkMetaData);
      this.services['ApiBusManager'].init(initOptions, this.instanceId, sdkMetaData);
      this.services['Requester'].init(initOptions, this.instanceId, sdkMetaData);
      this.services['Container'].init(initOptions, this.instanceId, sdkMetaData);
      this.services['Security'].init(initOptions, this.instanceId, sdkMetaData);
      this.services['EventCenter'].init(initOptions, this.instanceId, sdkMetaData);
      this.services['GlobalData'].init(initOptions, this.instanceId, sdkMetaData);
    }
  }, {
    key: "update",
    value: function update(paymentContext) {
      for (var serviceName in this.services) {
        this.services[serviceName].update(paymentContext);
      }
      for (var _serviceName in this.extendServices) {
        this.extendServices[_serviceName].update(paymentContext);
      }
    }
  }, {
    key: "getService",
    value: function getService(serviceName) {
      if (this.extendServices[serviceName]) {
        return this.extendServices[serviceName];
      }
      return this.services[serviceName];
    }
  }, {
    key: "registerService",
    value: function registerService(serviceName, service) {
      this.extendServices[serviceName] = service;
    }
  }], [{
    key: "getInstance",
    value: function getInstance(instanceId) {
      if (!ServiceProvider.ProvidersMapping[instanceId]) {
        ServiceProvider.ProvidersMapping[instanceId] = new ServiceProvider(instanceId);
      }
      return ServiceProvider.ProvidersMapping[instanceId];
    }
  }]);
  return ServiceProvider;
}();
_defineProperty(ServiceProvider, "ProvidersMapping", {});