"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EntrySym = exports.EntryOpsSym = exports.EntryOps = exports.Entry = void 0;
exports.makeEntry = makeEntry;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/STM/Versioned"));

var _TRefInternal = /*#__PURE__*/require("@effect/core/stm/TRef/operations/_internal/TRefInternal");

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;

const EntrySym = /*#__PURE__*/Symbol.for("@effect/core/stm/STM/Entry");
/**
 * @tsplus type ets/Entry
 * @tsplus companion ets/Entry/Ops
 */

exports.EntrySym = EntrySym;

class Entry {
  constructor(use) {
    this.use = use;
    this[_a] = EntrySym;
  }

}

exports.Entry = Entry;
_a = EntrySym;
/**
 * @tsplus static ets/Entry/Ops __call
 */

function makeEntry(tref0, isNew0) {
  void 0;
  const versioned = tref0.versioned;
  const ops = new EntryOps(tref0, versioned, versioned.value, isNew0, false);
  return new Entry(f => f(ops));
}

const EntryOpsSym = /*#__PURE__*/Symbol.for("@effect/core/stm/STM/Entry/Ops");
exports.EntryOpsSym = EntryOpsSym;

class EntryOps {
  constructor(tref, expected, newValue, isNew, isChanged) {
    this[_b] = EntryOpsSym;
    this.tref = tref;
    this.expected = expected;
    this.newValue = newValue;
    this.isNew = isNew;
    this._isChanged = isChanged;
  }

  unsafeSet(value) {
    this._isChanged = true;
    this.newValue = value;
  }

  unsafeGet() {
    return this.newValue;
  }

  commit() {
    void 0;
    this.tref.versioned = tsplus_module_1.make(this.newValue);
  }

  copy() {
    const ops = new EntryOps(this.tref, this.expected, this.newValue, this.isNew, this.isChanged());
    return new Entry(f => f(ops));
  }

  isInvalid() {
    return !this.isValid();
  }

  isValid() {
    void 0;
    return this.tref.versioned === this.expected;
  }

  isChanged() {
    return this._isChanged;
  }

  toString() {
    return `Entry(expected.value = ${this.expected.value}, newValue = ${this.newValue}, tref = ${this.tref}, isChanged = ${this.isChanged()})`;
  }

}

exports.EntryOps = EntryOps;
_b = EntryOpsSym;
//# sourceMappingURL=Entry.js.map