"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IntervalSym = exports.Interval = void 0;
exports.after = after;
exports.before = before;
exports.intersect = exports.fromStartEndMillis = exports.empty = void 0;
exports.intersect_ = intersect_;
exports.isEmpty = void 0;
exports.isNonEmpty = isNonEmpty;
exports.lessThan = void 0;
exports.lessThan_ = lessThan_;
exports.max = void 0;
exports.max_ = max_;
exports.min_ = exports.min = void 0;
exports.size = size;
exports.union = void 0;
exports.union_ = union_;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/prelude/Ord/common"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/prelude/Ord/operations"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Duration"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/definition"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fromStartEndMillis = fromStartEndMillis_1;
exports.fromStartEndMillis = fromStartEndMillis;
const min_ = min_1;
exports.min_ = min_;
const isEmpty = isEmpty_1;
exports.isEmpty = isEmpty;
const IntervalSym = /*#__PURE__*/Symbol.for("@effect/core/io/Schedule/Interval");
exports.IntervalSym = IntervalSym;
const Interval = {
  $: {}
};
/**
 * An `Interval` of zero-width.
 *
 * @tsplus static ets/Schedule/Interval/Ops empty
 */

exports.Interval = Interval;
const empty_1 = /*#__PURE__*/fromStartEndMillis_1(0, 0);
const empty = empty_1;
/**
 * Constructs a new interval from the two specified endpoints. If the start
 * endpoint greater than the end endpoint, then a zero size interval will be
 * returned.
 *
 * @tsplus static ets/Schedule/Interval/Ops __call
 */

exports.empty = empty;

function fromStartEndMillis_1(startMilliseconds, endMilliseconds) {
  return startMilliseconds > endMilliseconds ? empty_1 : {
    [IntervalSym]: IntervalSym,
    startMillis: startMilliseconds,
    endMillis: endMilliseconds
  };
}
/**
 * @tsplus operator ets/Schedule/Interval <
 * @tsplus fluent ets/Schedule/Interval lessThan
 */


function lessThan_(self, that) {
  return min_1(self, that) === self;
}
/**
 * @tsplus static ets/Schedule/Interval/Aspects lessThan
 */


const lessThan = that => self => lessThan_(self, that);
/**
 * @tsplus fluent ets/Schedule/Interval min
 */


exports.lessThan = lessThan;

function min_1(self, that) {
  if (self.endMillis <= that.startMillis) return self;
  if (that.endMillis <= self.startMillis) return that;
  if (self.startMillis < that.startMillis) return self;
  if (that.startMillis < self.startMillis) return that;
  if (self.endMillis <= that.endMillis) return self;
  return that;
}
/**
 * @tsplus static ets/Schedule/Interval/Aspects min
 */


const min = that => self => min_(self, that);
/**
 * @tsplus fluent ets/Schedule/Interval max
 */


exports.min = min;

function max_(self, that) {
  return min_1(self, that) === self ? that : self;
}
/**
 * @tsplus static ets/Schedule/Interval/Aspects max
 */


const max = that => self => max_(self, that);
/**
 * @tsplus getter ets/Schedule/Interval isEmpty
 */


exports.max = max;

function isEmpty_1(self) {
  return self.startMillis >= self.endMillis;
}
/**
 * @tsplus getter ets/Schedule/Interval isNonEmpty
 */


function isNonEmpty(self) {
  return !isEmpty_1(self);
}
/**
 * @tsplus fluent ets/Schedule/Interval intersect
 */


function intersect_(self, that) {
  const start = tsplus_module_2.min(tsplus_module_1.number)(self.startMillis, that.startMillis);
  const end = tsplus_module_2.max(tsplus_module_1.number)(self.endMillis, that.endMillis);
  return fromStartEndMillis_1(start, end);
}
/**
 * @tsplus static ets/Schedule/Interval/Aspects intersect
 */


const intersect = that => self => intersect_(self, that);
/**
 * @tsplus getter ets/Schedule/Interval size
 */


exports.intersect = intersect;

function size(self) {
  return new tsplus_module_3.Duration(self.endMillis - self.startMillis);
}
/**
 * @tsplus fluent ets/Schedule/Interval union
 */


function union_(self, that) {
  const start = tsplus_module_2.max(tsplus_module_1.number)(self.startMillis, that.startMillis);
  const end = tsplus_module_2.min(tsplus_module_1.number)(self.endMillis, that.endMillis);
  return start < end ? tsplus_module_4.none : tsplus_module_4.some(fromStartEndMillis_1(start, end));
}
/**
 * @tsplus static ets/Schedule/Interval/Aspects union
 */


const union = that => self => union_(self, that);
/**
 * Construct an `Interval` that includes all time equal to and after the
 * specified start time.
 *
 * @tsplus static ets/Schedule/Interval/Ops after
 */


exports.union = union;

function after(startMilliseconds) {
  return fromStartEndMillis_1(startMilliseconds, Number.MAX_SAFE_INTEGER);
}
/**
 * Construct an `Interval` that includes all time equal to and before the
 * specified end time.
 *
 * @tsplus static ets/Schedule/Interval before
 */


function before(endMilliseconds) {
  return fromStartEndMillis_1(Number.MIN_SAFE_INTEGER, endMilliseconds);
}
//# sourceMappingURL=Interval.js.map