"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: !0
});

var _exportNames = {
  getToken: !0,
  AmosFetch: !0,
  AmosEnum: !0
};

Object.defineProperty(exports, "AmosEnum", {
  enumerable: !0,
  get: function() {
    return _AmosEnum.default;
  }
}), exports.AmosFetch = void 0, exports.getToken = getToken;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _amosProcessor = require("amos-processor"), _AmosEnum = _interopRequireDefault(require("amos-processor/lib/enum/AmosEnum")), _amosTool = require("amos-tool"), _config = _interopRequireDefault(require("amos-processor/lib/config")), _utils = require("amos-processor/lib/utils");

Object.keys(_utils).forEach((function(e) {
  "default" !== e && "__esModule" !== e && (Object.prototype.hasOwnProperty.call(_exportNames, e) || e in exports && exports[e] === _utils[e] || Object.defineProperty(exports, e, {
    enumerable: !0,
    get: function() {
      return _utils[e];
    }
  }));
}));

var _permission = require("amos-processor/lib/config/permission");

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) {
      (0, _defineProperty2.default)(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;
}

Object.keys(_permission).forEach((function(e) {
  "default" !== e && "__esModule" !== e && (Object.prototype.hasOwnProperty.call(_exportNames, e) || e in exports && exports[e] === _permission[e] || Object.defineProperty(exports, e, {
    enumerable: !0,
    get: function() {
      return _permission[e];
    }
  }));
}));

var lsTool = _amosTool.Store.lsTool, defaultHeaders = function() {
  return window.isIotPluginsToAmos ? window.iotRequestInfo.staticHeader : {
    appKey: "AMOS_IOT",
    product: "AMOS_IOT_WEB"
  };
};

function getToken() {
  return lsTool.read(_config.default.token);
}

var AmosFetch = {
  _fetch: function(e) {
    return function(r, t, o) {
      if (!_amosProcessor.AmosFetch[e]) throw new Error("AmosFetch: ´íÎóµÄÇëÇó[".concat(e, "]"));
      var s = _amosTool.utils.merge({
        headers: _objectSpread(_objectSpread({}, defaultHeaders()), {}, {
          token: getToken()
        })
      }, t);
      return _amosProcessor.AmosFetch[e](r, {
        params: s,
        data: o
      });
    };
  },
  get: function(e) {
    var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
    return AmosFetch._fetch("get")(e, t, o);
  },
  put: function(e) {
    var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
    return AmosFetch._fetch("put")(e, t, o);
  },
  post: function(e) {
    var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
    return AmosFetch._fetch("post")(e, t, o);
  },
  del: function(e) {
    var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, t = r.params, o = r.data;
    return AmosFetch._fetch("del")(e, t, o);
  }
};

exports.AmosFetch = AmosFetch;