"use strict";

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/es.promise.js");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SnpTable = void 0;

require("regenerator-runtime/runtime.js");

require("core-js/modules/es.array.map.js");

require("core-js/modules/es.object.define-property.js");

var _common = require("../../common");

var _snpTableRow = require("../snp-table-row");

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

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, 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; }

var SnpTable = /*#__PURE__*/function () {
  function SnpTable() {
    _classCallCheck(this, SnpTable);
  }

  _createClass(SnpTable, null, [{
    key: "generate",
    value: function () {
      var _generate = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(code, rows) {
        var server, response;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                server = new _common.APIServer();
                _context.next = 3;
                return server.post("service/genes/gene/".concat(code, "/snp-table"), undefined, JSON.parse(JSON.stringify(rows)));

              case 3:
                response = _context.sent;

                if (!response.error) {
                  _context.next = 6;
                  break;
                }

                throw new _common.APIResponseError("Error while generating SNP table", response);

              case 6:
                return _context.abrupt("return", response.data.map(function (row) {
                  return _snpTableRow.SnpTableRow.apiFactory(row);
                }));

              case 7:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));

      function generate(_x, _x2) {
        return _generate.apply(this, arguments);
      }

      return generate;
    }()
  }]);

  return SnpTable;
}();

exports.SnpTable = SnpTable;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9nZW5lcy9zbnAtdGFibGUvc25wLXRhYmxlLnRzIl0sIm5hbWVzIjpbIlNucFRhYmxlIiwiY29kZSIsInJvd3MiLCJzZXJ2ZXIiLCJBUElTZXJ2ZXIiLCJwb3N0IiwidW5kZWZpbmVkIiwiSlNPTiIsInBhcnNlIiwic3RyaW5naWZ5IiwicmVzcG9uc2UiLCJlcnJvciIsIkFQSVJlc3BvbnNlRXJyb3IiLCJkYXRhIiwibWFwIiwicm93IiwiU25wVGFibGVSb3ciLCJhcGlGYWN0b3J5Il0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OztBQUFBOztBQUNBOzs7Ozs7Ozs7Ozs7SUFHYUEsUTs7Ozs7Ozs7OEVBQ1gsaUJBQ0VDLElBREYsRUFFRUMsSUFGRjtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFJUUMsZ0JBQUFBLE1BSlIsR0FJaUIsSUFBSUMsaUJBQUosRUFKakI7QUFBQTtBQUFBLHVCQUt5QkQsTUFBTSxDQUFDRSxJQUFQLDhCQUNDSixJQURELGlCQUVyQkssU0FGcUIsRUFHckJDLElBQUksQ0FBQ0MsS0FBTCxDQUFXRCxJQUFJLENBQUNFLFNBQUwsQ0FBZVAsSUFBZixDQUFYLENBSHFCLENBTHpCOztBQUFBO0FBS1FRLGdCQUFBQSxRQUxSOztBQUFBLHFCQVdNQSxRQUFR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