'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var utils = require('../utils.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]
 * @return {GetCoinInfoInstance}
 */
function GetCoinInfo(apiInstance, factoryAxiosOptions) {
  return getCoinInfo;
  /**
   * Get nonce for new transaction: last transaction number + 1
   * @typedef {Function} GetCoinInfoInstance
   * @param {string|number} coin
   * @param {import('axios').AxiosRequestConfig} [axiosOptions]
   * @return {Promise<CoinInfo>}
   */
  function getCoinInfo(coin, axiosOptions) {
    axiosOptions = _objectSpread(_objectSpread({}, factoryAxiosOptions), axiosOptions);
    var coinInfoPromise;
    if (utils.isCoinId(coin)) {
      coinInfoPromise = apiInstance.get("coin_info_by_id/".concat(coin), axiosOptions);
    } else if (utils.isCoinSymbol(coin)) {
      coinInfoPromise = apiInstance.get("coin_info/".concat(coin), axiosOptions);
    } else {
      return Promise.reject(new Error('Invalid coin'));
    }
    return coinInfoPromise.then(function (response) {
      response.data.id = Number(response.data.id);
      return response.data;
    });
  }
}

/**
 * @typedef {object} CoinInfo
 * @property {number|string} id
 * @property {string} name
 * @property {string} symbol
 * @property {number|string} volume
 * @property {number|string} crr
 * @property {number|string} reserve_balance
 * @property {number|string} max_supply
 * @property {string|null} owner_address
 */

module.exports = GetCoinInfo;
