'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
var _regeneratorRuntime = require('@babel/runtime/regenerator');
var minterjsUtil = require('minterjs-util');
var replaceCoin = require('./replace-coin.js');

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

/**
 * @param {MinterApiInstance} apiInstance
 * @param {import('axios').AxiosRequestConfig} [factoryAxiosOptions]
 * @param {import('axios').AxiosRequestConfig} [factoryExtraAxiosOptions] - options for getting coin id
 * @return {GetPoolInfoInstance}
 */
function GetPoolInfo(apiInstance, factoryAxiosOptions, factoryExtraAxiosOptions) {
  var replaceCoinSymbolByPath = replaceCoin.ReplaceCoinSymbolByPath(apiInstance, factoryExtraAxiosOptions);
  /**
   * @typedef {Function} GetPoolInfoInstance
   * @param {number|string} coin0 - first coin id
   * @param {number|string} coin1 - second coin id
   * @param {import('axios').AxiosRequestConfig} [axiosOptions]
   * @param {import('axios').AxiosRequestConfig} [extraAxiosOptions]
   * @return {Promise<PoolInfo>}
   */
  return /*#__PURE__*/function () {
    var _getPoolInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(coin0, coin1, axiosOptions, extraAxiosOptions) {
      var coins;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return replaceCoinSymbolByPath([coin0, coin1], ['0', '1'], undefined, extraAxiosOptions);
          case 2:
            coins = _context.sent;
            return _context.abrupt("return", apiInstance.get("swap_pool/".concat(coins[0], "/").concat(coins[1]), _objectSpread(_objectSpread({}, factoryAxiosOptions), axiosOptions)).then(function (response) {
              response.data.id = Number(response.data.id);
              return _objectSpread(_objectSpread({}, response.data), {}, {
                id: Number(response.data.id),
                liquidity: minterjsUtil.convertFromPip(response.data.liquidity),
                amount0: minterjsUtil.convertFromPip(response.data.amount0),
                amount1: minterjsUtil.convertFromPip(response.data.amount1)
              });
            }));
          case 4:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    function getPoolInfo(_x, _x2, _x3, _x4) {
      return _getPoolInfo.apply(this, arguments);
    }
    return getPoolInfo;
  }();
}

/**
 * @typedef {object} PoolInfo
 * @property {number} id
 * @property {string|number} amount0
 * @property {string|number} amount1
 * @property {string|number} liquidity
 */

module.exports = GetPoolInfo;
