"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var transaction_exports = {};
__export(transaction_exports, {
  Transaction: () => Transaction,
  TransactionTree: () => TransactionTree,
  TreeEvent: () => TreeEvent
});
module.exports = __toCommonJS(transaction_exports);
var import_runtime = require("@protobuf-ts/runtime");
var import_runtime2 = require("@protobuf-ts/runtime");
var import_runtime3 = require("@protobuf-ts/runtime");
var import_runtime4 = require("@protobuf-ts/runtime");
var import_event = require("./event.cjs");
var import_trace_context = require("./trace_context.cjs");
var import_timestamp = require("../../../../../google/protobuf/timestamp.cjs");
var import_event2 = require("./event.cjs");
var import_event3 = require("./event.cjs");
class TreeEvent$Type extends import_runtime4.MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.TreeEvent", [
      {
        no: 1,
        name: "created",
        kind: "message",
        oneof: "kind",
        T: () => import_event3.CreatedEvent
      },
      {
        no: 2,
        name: "exercised",
        kind: "message",
        oneof: "kind",
        T: () => import_event2.ExercisedEvent
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.kind = { oneofKind: void 0 };
    if (value !== void 0)
      (0, import_runtime3.reflectionMergePartial)(this, message, value);
    return message;
  }
  internalBinaryRead(reader, length, options, target) {
    let message = target ?? this.create(), end = reader.pos + length;
    while (reader.pos < end) {
      let [fieldNo, wireType] = reader.tag();
      switch (fieldNo) {
        case /* com.daml.ledger.api.v2.CreatedEvent created */
        1:
          message.kind = {
            oneofKind: "created",
            created: import_event3.CreatedEvent.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.kind.created
            )
          };
          break;
        case /* com.daml.ledger.api.v2.ExercisedEvent exercised */
        2:
          message.kind = {
            oneofKind: "exercised",
            exercised: import_event2.ExercisedEvent.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.kind.exercised
            )
          };
          break;
        default:
          let u = options.readUnknownField;
          if (u === "throw")
            throw new globalThis.Error(
              `Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`
            );
          let d = reader.skip(wireType);
          if (u !== false)
            (u === true ? import_runtime2.UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.kind.oneofKind === "created")
      import_event3.CreatedEvent.internalBinaryWrite(
        message.kind.created,
        writer.tag(1, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.kind.oneofKind === "exercised")
      import_event2.ExercisedEvent.internalBinaryWrite(
        message.kind.exercised,
        writer.tag(2, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const TreeEvent = new TreeEvent$Type();
class TransactionTree$Type extends import_runtime4.MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.TransactionTree", [
      {
        no: 1,
        name: "update_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "command_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "workflow_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 4,
        name: "effective_at",
        kind: "message",
        T: () => import_timestamp.Timestamp
      },
      {
        no: 5,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 6,
        name: "events_by_id",
        kind: "map",
        K: 5,
        V: { kind: "message", T: () => TreeEvent }
      },
      {
        no: 7,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 8,
        name: "trace_context",
        kind: "message",
        T: () => import_trace_context.TraceContext
      },
      { no: 9, name: "record_time", kind: "message", T: () => import_timestamp.Timestamp }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.updateId = "";
    message.commandId = "";
    message.workflowId = "";
    message.offset = 0n;
    message.eventsById = {};
    message.synchronizerId = "";
    if (value !== void 0)
      (0, import_runtime3.reflectionMergePartial)(this, message, value);
    return message;
  }
  internalBinaryRead(reader, length, options, target) {
    let message = target ?? this.create(), end = reader.pos + length;
    while (reader.pos < end) {
      let [fieldNo, wireType] = reader.tag();
      switch (fieldNo) {
        case /* string update_id */
        1:
          message.updateId = reader.string();
          break;
        case /* string command_id */
        2:
          message.commandId = reader.string();
          break;
        case /* string workflow_id */
        3:
          message.workflowId = reader.string();
          break;
        case /* google.protobuf.Timestamp effective_at */
        4:
          message.effectiveAt = import_timestamp.Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.effectiveAt
          );
          break;
        case /* int64 offset */
        5:
          message.offset = reader.int64().toBigInt();
          break;
        case /* map<int32, com.daml.ledger.api.v2.TreeEvent> events_by_id */
        6:
          this.binaryReadMap6(message.eventsById, reader, options);
          break;
        case /* string synchronizer_id */
        7:
          message.synchronizerId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.TraceContext trace_context */
        8:
          message.traceContext = import_trace_context.TraceContext.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.traceContext
          );
          break;
        case /* google.protobuf.Timestamp record_time */
        9:
          message.recordTime = import_timestamp.Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.recordTime
          );
          break;
        default:
          let u = options.readUnknownField;
          if (u === "throw")
            throw new globalThis.Error(
              `Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`
            );
          let d = reader.skip(wireType);
          if (u !== false)
            (u === true ? import_runtime2.UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  binaryReadMap6(map, reader, options) {
    let len = reader.uint32(), end = reader.pos + len, key, val;
    while (reader.pos < end) {
      let [fieldNo, wireType] = reader.tag();
      switch (fieldNo) {
        case 1:
          key = reader.int32();
          break;
        case 2:
          val = TreeEvent.internalBinaryRead(
            reader,
            reader.uint32(),
            options
          );
          break;
        default:
          throw new globalThis.Error(
            "unknown map entry field for com.daml.ledger.api.v2.TransactionTree.events_by_id"
          );
      }
    }
    map[key ?? 0] = val ?? TreeEvent.create();
  }
  internalBinaryWrite(message, writer, options) {
    if (message.updateId !== "")
      writer.tag(1, import_runtime.WireType.LengthDelimited).string(message.updateId);
    if (message.commandId !== "")
      writer.tag(2, import_runtime.WireType.LengthDelimited).string(message.commandId);
    if (message.workflowId !== "")
      writer.tag(3, import_runtime.WireType.LengthDelimited).string(message.workflowId);
    if (message.effectiveAt)
      import_timestamp.Timestamp.internalBinaryWrite(
        message.effectiveAt,
        writer.tag(4, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.offset !== 0n)
      writer.tag(5, import_runtime.WireType.Varint).int64(message.offset);
    for (let k of globalThis.Object.keys(message.eventsById)) {
      writer.tag(6, import_runtime.WireType.LengthDelimited).fork().tag(1, import_runtime.WireType.Varint).int32(parseInt(k));
      writer.tag(2, import_runtime.WireType.LengthDelimited).fork();
      TreeEvent.internalBinaryWrite(
        message.eventsById[k],
        writer,
        options
      );
      writer.join().join();
    }
    if (message.synchronizerId !== "")
      writer.tag(7, import_runtime.WireType.LengthDelimited).string(message.synchronizerId);
    if (message.traceContext)
      import_trace_context.TraceContext.internalBinaryWrite(
        message.traceContext,
        writer.tag(8, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.recordTime)
      import_timestamp.Timestamp.internalBinaryWrite(
        message.recordTime,
        writer.tag(9, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const TransactionTree = new TransactionTree$Type();
class Transaction$Type extends import_runtime4.MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.Transaction", [
      {
        no: 1,
        name: "update_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "command_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "workflow_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 4,
        name: "effective_at",
        kind: "message",
        T: () => import_timestamp.Timestamp
      },
      {
        no: 5,
        name: "events",
        kind: "message",
        repeat: 2,
        T: () => import_event.Event
      },
      {
        no: 6,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 7,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 8,
        name: "trace_context",
        kind: "message",
        T: () => import_trace_context.TraceContext
      },
      { no: 9, name: "record_time", kind: "message", T: () => import_timestamp.Timestamp }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.updateId = "";
    message.commandId = "";
    message.workflowId = "";
    message.events = [];
    message.offset = 0n;
    message.synchronizerId = "";
    if (value !== void 0)
      (0, import_runtime3.reflectionMergePartial)(this, message, value);
    return message;
  }
  internalBinaryRead(reader, length, options, target) {
    let message = target ?? this.create(), end = reader.pos + length;
    while (reader.pos < end) {
      let [fieldNo, wireType] = reader.tag();
      switch (fieldNo) {
        case /* string update_id */
        1:
          message.updateId = reader.string();
          break;
        case /* string command_id */
        2:
          message.commandId = reader.string();
          break;
        case /* string workflow_id */
        3:
          message.workflowId = reader.string();
          break;
        case /* google.protobuf.Timestamp effective_at */
        4:
          message.effectiveAt = import_timestamp.Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.effectiveAt
          );
          break;
        case /* repeated com.daml.ledger.api.v2.Event events */
        5:
          message.events.push(
            import_event.Event.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* int64 offset */
        6:
          message.offset = reader.int64().toBigInt();
          break;
        case /* string synchronizer_id */
        7:
          message.synchronizerId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.TraceContext trace_context */
        8:
          message.traceContext = import_trace_context.TraceContext.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.traceContext
          );
          break;
        case /* google.protobuf.Timestamp record_time */
        9:
          message.recordTime = import_timestamp.Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.recordTime
          );
          break;
        default:
          let u = options.readUnknownField;
          if (u === "throw")
            throw new globalThis.Error(
              `Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`
            );
          let d = reader.skip(wireType);
          if (u !== false)
            (u === true ? import_runtime2.UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.updateId !== "")
      writer.tag(1, import_runtime.WireType.LengthDelimited).string(message.updateId);
    if (message.commandId !== "")
      writer.tag(2, import_runtime.WireType.LengthDelimited).string(message.commandId);
    if (message.workflowId !== "")
      writer.tag(3, import_runtime.WireType.LengthDelimited).string(message.workflowId);
    if (message.effectiveAt)
      import_timestamp.Timestamp.internalBinaryWrite(
        message.effectiveAt,
        writer.tag(4, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    for (let i = 0; i < message.events.length; i++)
      import_event.Event.internalBinaryWrite(
        message.events[i],
        writer.tag(5, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.offset !== 0n)
      writer.tag(6, import_runtime.WireType.Varint).int64(message.offset);
    if (message.synchronizerId !== "")
      writer.tag(7, import_runtime.WireType.LengthDelimited).string(message.synchronizerId);
    if (message.traceContext)
      import_trace_context.TraceContext.internalBinaryWrite(
        message.traceContext,
        writer.tag(8, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.recordTime)
      import_timestamp.Timestamp.internalBinaryWrite(
        message.recordTime,
        writer.tag(9, import_runtime.WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const Transaction = new Transaction$Type();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Transaction,
  TransactionTree,
  TreeEvent
});
//# sourceMappingURL=transaction.cjs.map