"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isTraceElement = exports.empty = exports.TraceElementSym = exports.TraceElement = exports.SourceLocation = exports.NoLocation = void 0;
exports.parse = parse;
exports.sourceLocation = void 0;
exports.stringify = stringify;

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

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

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 isTraceElement = isTraceElement_1;
exports.isTraceElement = isTraceElement;
const sourceLocation = sourceLocation_1;
exports.sourceLocation = sourceLocation;
const TraceElementSym = /*#__PURE__*/Symbol.for("@effect/core/io/TraceElement");
exports.TraceElementSym = TraceElementSym;
const TraceElement = {
  $: {}
};
exports.TraceElement = TraceElement;

class NoLocation {
  constructor() {
    this._tag = "NoLocation";
    this[_a] = TraceElementSym;
  }

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

  [tsplus_module_2.Equals.sym](u) {
    return isTraceElement_1(u) && u._tag === "NoLocation";
  }

}

exports.NoLocation = NoLocation;

class SourceLocation {
  constructor(fileName, lineNumber, columnNumber) {
    this.fileName = fileName;
    this.lineNumber = lineNumber;
    this.columnNumber = columnNumber;
    this._tag = "SourceLocation";
    this[_b] = TraceElementSym;
  }

  [(_b = TraceElementSym, tsplus_module_1.Hash.sym)]() {
    return tsplus_module_1.combine(tsplus_module_1.hashString(this._tag), tsplus_module_1.combine(tsplus_module_1.hashString(this.fileName), tsplus_module_1.combine(tsplus_module_1.hashNumber(this.lineNumber), tsplus_module_1.hashNumber(this.columnNumber))));
  }

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

}
/**
 * @tsplus static ets/TraceElement/Ops isTraceElement
 */


exports.SourceLocation = SourceLocation;

function isTraceElement_1(u) {
  return typeof u === "object" && u != null && TraceElementSym in u;
} // -----------------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------------

/**
 * @tsplus static ets/TraceElement/Ops empty
 */


const empty_1 = /*#__PURE__*/new NoLocation();
const empty = empty_1;
/**
 * @tsplus static ets/TraceElement/Ops __call
 */

exports.empty = empty;

function sourceLocation_1(fileName, lineNumber, columnNumber) {
  return new SourceLocation(fileName, lineNumber, columnNumber);
} // -----------------------------------------------------------------------------
// Operations
// -----------------------------------------------------------------------------


const LOCATION_REGEX = /^(.*?):(\d*?):(\d*?)$/;
/**
 * @tsplus static ets/TraceElement/Ops parse
 */

function parse(trace) {
  if (trace) {
    const parts = trace.match(LOCATION_REGEX);

    if (parts) {
      const fileName = parts[1].trim();
      const lineNumber = Number.parseInt(parts[2]);
      const columnNumber = Number.parseInt(parts[3]);
      return sourceLocation_1(fileName, lineNumber, columnNumber);
    }

    return empty_1;
  }

  return empty_1;
}
/**
 * @tsplus getter ets/TraceElement stringify
 */


function stringify(self) {
  switch (self._tag) {
    case "NoLocation":
      {
        return "";
      }

    case "SourceLocation":
      {
        return `${self.fileName}:${self.lineNumber}:${self.columnNumber}`;
      }
  }
}
//# sourceMappingURL=definition.js.map