var _a, _b;

import * as tsplus_module_1 from "@tsplus/stdlib/structure/Hash";
import * as tsplus_module_2 from "@tsplus/stdlib/structure/Equals";
export const isTraceElement = isTraceElement_1;
export const sourceLocation = sourceLocation_1;
export const TraceElementSym = /*#__PURE__*/Symbol.for("@effect/core/io/TraceElement");
export const TraceElement = {
  $: {}
};
export 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";
  }

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

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();
export const empty = empty_1;
/**
 * @tsplus static ets/TraceElement/Ops __call
 */

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


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

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

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

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