text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const constants_1 = require("./constants");
  const utils_1 = require("./utils");
  exports.apiMethod = (options = {}) => async function apiHandler(...args) {
      const { method = constants_1.GET, path = '', urlParams = [], validator, defaultData = {}, retry = false, } = options;
      if (urlParams.length > 0 && args.length < urlParams.length) {
          throw new Error(`This endpoint must be supplied with the following parameters: ${urlParams.toString()}`);
      }
      const data = {
          ...defaultData,
          ...(args.length > urlParams.length &&
              typeof args[urlParams.length] === 'object'
              ? args[urlParams.length]
              : {}),
      };
      if (validator) {
          validator(data);
      }
      const resolvedURLObject = urlParams.reduce((accumulator, param, i) => {
          const value = args[i];
          if (typeof value !== 'string' && typeof value !== 'number') {
              throw new Error('Parameter must be a string or a number');
          }
          return {
              ...accumulator,
              [param]: typeof value === 'number' ? value.toString() : value,
          };
      }, {});
      const requestData = {
          headers: this.headers,
          method,
          url: utils_1.solveURLParams(`${this.resourcePath}${path}`, resolvedURLObject),
      };
      if (Object.keys(data).length > 0) {
          if (method === constants_1.GET) {
              requestData.url += `?${utils_1.toQueryString(data)}`;
          }
          else {
              requestData.data = data;
          }
      }
      return this.request(requestData, retry);
  };
  //# sourceMappingURL=api_method.js.map