"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.dayOfWeek = dayOfWeek;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Cause/errors"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/die"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Schedule/Interval"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Schedule/Decision"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Tuple/make"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/succeedNow"));

var _makeWithState = /*#__PURE__*/require("@effect/core/io/Schedule/operations/_internal/makeWithState");

var _time = /*#__PURE__*/require("@effect/core/io/Schedule/operations/_internal/time");

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 fileName_1 = "(@effect/core) _src/io/Schedule/operations/dayOfWeek.ts";

/**
 * Cron-like schedule that recurs every specified `day` of each week. It
 * triggers at zero hour of the week. Producing a count of repeats: 0, 1, 2.
 *
 * NOTE: `day` parameter is validated lazily. Must be in range 1 (Monday)...7
 * (Sunday).
 *
 * @tsplus static ets/Schedule dayOfWeek
 */
function dayOfWeek(day) {
  return (0, _makeWithState.makeWithState)(0, (now, _, state) => {
    if (!Number.isInteger(day) || day < 0 || 7 < day) {
      return tsplus_module_2.die(() => new tsplus_module_1.IllegalArgumentException(`Invalid argument in: dayOfWeek(${day}). Must be in range 1 (Monday)...7 (Sunday)`), fileName_1 + ":20:24");
    }

    const d = (0, _time.nextDay)(now, day);
    const start = Math.max((0, _time.beginningOfDay)(d), now);
    const end = (0, _time.endOfDay)(d);
    const interval = tsplus_module_3.fromStartEndMillis(start, end);
    return tsplus_module_6.succeedNow(tsplus_module_5.make(state + 1, state, tsplus_module_4._continue(interval)), fileName_1 + ":30:29");
  });
}
//# sourceMappingURL=dayOfWeek.js.map