import "core-js/modules/es6.string.iterator";
import "core-js/modules/es6.array.from";
import "core-js/modules/es6.regexp.to-string";
import "core-js/modules/es7.symbol.async-iterator";
import "core-js/modules/es6.symbol";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/es6.array.iterator";
import "core-js/modules/es6.object.keys";
import "core-js/modules/es6.number.constructor";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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); return Constructor; }

import _moment from 'moment';
import { isNil } from './predicate';
import { times } from './utils';
var defaultRand = Math.random;
export var Random =
/*#__PURE__*/
function () {
  function Random() {
    var rand = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRand;

    _classCallCheck(this, Random);

    this._rand = rand;
  }

  _createClass(Random, [{
    key: "boolean",
    value: function boolean() {
      return this._rand() > 0.5;
    }
  }, {
    key: "number",
    value: function number() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var min = isNil(options.min) ? Number.MIN_VALUE : options.min;
      var max = isNil(options.max) ? Number.MAX_VALUE : options.max;
      var delta = this._rand() * (max - min);
      return min + delta;
    }
  }, {
    key: "integer",
    value: function integer() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var min = Math.ceil(isNil(options.min) ? Number.MIN_VALUE : options.min);
      var max = Math.floor(isNil(options.max) ? Number.MAX_VALUE : options.max);
      var delta = Math.floor(this._rand() * (max - min + 1));
      return min + delta;
    }
  }, {
    key: "oneOf",
    value: function oneOf(values) {
      return values[Math.floor(this._rand() * values.length)];
    }
  }, {
    key: "oneToOne",
    value: function oneToOne(values, index) {
      return values[index];
    }
  }, {
    key: "setOf",
    value: function setOf(values, options) {
      var _this = this;

      var count = this.integer(_objectSpread({
        min: 0,
        max: values.length
      }, options));

      var copy = _toConsumableArray(values);

      return times(count, function () {
        var value = _this.oneOf(copy);

        copy.splice(copy.indexOf(value), 1);
        return value;
      });
    }
  }, {
    key: "date",
    value: function date() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var min = isNil(options.min) ? new Date(0) : options.min;
      var max = isNil(options.max) ? new Date(Date.now()) : options.max;
      var minMls = min.getTime();
      var maxMls = max.getTime();
      var time = this.integer({
        min: minMls,
        max: maxMls
      });
      return new Date(time);
    }
  }, {
    key: "moment",
    value: function moment() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var min = isNil(options.min) ? _moment(0) : options.min;
      var max = isNil(options.max) ? _moment() : options.max;
      var minMls = +min;
      var maxMls = +max;
      var time = this.integer({
        min: minMls,
        max: maxMls
      });
      return _moment(time);
    }
  }]);

  return Random;
}();