import * as tsplus_module_1 from "@tsplus/stdlib/prelude/Ord/common";
import * as tsplus_module_2 from "@tsplus/stdlib/prelude/Ord/operations";
import * as tsplus_module_3 from "@tsplus/stdlib/data/Duration";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Maybe/definition";
export const fromStartEndMillis = fromStartEndMillis_1;
export const min_ = min_1;
export const isEmpty = isEmpty_1;
export const IntervalSym = /*#__PURE__*/Symbol.for("@effect/core/io/Schedule/Interval");
export const Interval = {
  $: {}
};
/**
 * An `Interval` of zero-width.
 *
 * @tsplus static ets/Schedule/Interval/Ops empty
 */

const empty_1 = /*#__PURE__*/fromStartEndMillis_1(0, 0);
export 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
 */

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
 */


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

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

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
 */


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

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

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

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


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

export 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
 */

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

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

export 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
 */

export 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
 */

export 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
 */

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