"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.State = exports.STMStateSym = exports.Running = exports.Interrupted = exports.Done = void 0;
exports.done = done;
exports.interrupted = void 0;
exports.isRunning = isRunning;
exports.running = exports.isState = void 0;
exports.unifyState = unifyState;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/structure/Hash"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/structure/Equals"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Exit/operations/succeed"));

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

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Exit/operations/fail"));

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

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; }

var _a, _b, _c;

const isState = isState_1;
exports.isState = isState;
const STMStateSym = /*#__PURE__*/Symbol.for("@effect/core/stm/STM/State");
exports.STMStateSym = STMStateSym;
const State = {};
/**
 * @tsplus unify ets/STM/State
 */

exports.State = State;

function unifyState(self) {
  return self;
}

class Done {
  constructor(exit) {
    this.exit = exit;
    this._tag = "Done";
    this[_a] = STMStateSym;
  }

  [(_a = STMStateSym, tsplus_module_1.Hash.sym)]() {
    return tsplus_module_1.combine(tsplus_module_1.hashString(this._tag), tsplus_module_1.hashUnknown(this.exit));
  }

  [tsplus_module_2.Equals.sym](that) {
    return isState_1(that) && this[tsplus_module_1.Hash.sym]() === that[tsplus_module_1.Hash.sym]();
  }

}

exports.Done = Done;

class Interrupted {
  constructor() {
    this._tag = "Interrupted";
    this[_b] = STMStateSym;
  }

  [(_b = STMStateSym, tsplus_module_1.Hash.sym)]() {
    return tsplus_module_1.hashString(this._tag);
  }

  [tsplus_module_2.Equals.sym](that) {
    return isState_1(that) && this[tsplus_module_1.Hash.sym]() === that[tsplus_module_1.Hash.sym]();
  }

}

exports.Interrupted = Interrupted;

class Running {
  constructor() {
    this._tag = "Running";
    this[_c] = STMStateSym;
  }

  [(_c = STMStateSym, tsplus_module_1.Hash.sym)]() {
    return tsplus_module_1.hashString(this._tag);
  }

  [tsplus_module_2.Equals.sym](that) {
    return isState_1(that) && this[tsplus_module_1.Hash.sym]() === that[tsplus_module_1.Hash.sym]();
  }

}
/**
 * @tsplus static ets/STM/State/Ops isState
 */


exports.Running = Running;

function isState_1(u) {
  return typeof u === "object" && u != null && STMStateSym in u;
}
/**
 * @tsplus static ets/STM/State/Ops done
 */


function done(exit) {
  switch (exit._tag) {
    case "Succeed":
      {
        return new Done(tsplus_module_3.succeed(exit.value));
      }

    case "Die":
      {
        return new Done(tsplus_module_4.die(exit.value));
      }

    case "Fail":
      {
        return new Done(tsplus_module_5.fail(exit.value));
      }

    case "Interrupt":
      {
        return new Done(tsplus_module_6.interrupt(exit.fiberId));
      }

    case "Retry":
      {
        throw new Error("Bug: done being called on TExit.Retry");
      }
  }
}
/**
 * @tsplus static ets/STM/State/Ops interrupted
 */


const interrupted = /*#__PURE__*/new Interrupted();
/**
 * @tsplus static ets/STM/State/Ops running
 */

exports.interrupted = interrupted;
const running = /*#__PURE__*/new Running();
/**
 * @tsplus fluent ets/STM/State isRunning
 */

exports.running = running;

function isRunning(self) {
  return self._tag === "Running";
}
//# sourceMappingURL=State.js.map