import { ServiceType } from "@protobuf-ts/runtime-rpc";
import { WireType } from "@protobuf-ts/runtime";
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
import { reflectionMergePartial } from "@protobuf-ts/runtime";
import { MessageType } from "@protobuf-ts/runtime";
import { AssignedEvent } from "./reassignment.js";
import { UnassignedEvent } from "./reassignment.js";
import { CreatedEvent } from "./event.js";
import { EventFormat } from "./transaction_filter.js";
import { TransactionFilter } from "./transaction_filter.js";
var ParticipantPermission = /* @__PURE__ */ ((ParticipantPermission2) => {
  ParticipantPermission2[ParticipantPermission2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
  ParticipantPermission2[ParticipantPermission2["SUBMISSION"] = 1] = "SUBMISSION";
  ParticipantPermission2[ParticipantPermission2["CONFIRMATION"] = 2] = "CONFIRMATION";
  ParticipantPermission2[ParticipantPermission2["OBSERVATION"] = 3] = "OBSERVATION";
  return ParticipantPermission2;
})(ParticipantPermission || {});
class GetActiveContractsRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetActiveContractsRequest", [
      {
        no: 1,
        name: "filter",
        kind: "message",
        T: () => TransactionFilter
      },
      {
        no: 2,
        name: "verbose",
        kind: "scalar",
        T: 8
      },
      {
        no: 3,
        name: "active_at_offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 4,
        name: "event_format",
        kind: "message",
        T: () => EventFormat
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.verbose = false;
    message.activeAtOffset = 0n;
    if (value !== void 0)
      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.TransactionFilter filter = 1 [deprecated = true] */
        1:
          message.filter = TransactionFilter.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.filter
          );
          break;
        case /* bool verbose = 2 [deprecated = true] */
        2:
          message.verbose = reader.bool();
          break;
        case /* int64 active_at_offset */
        3:
          message.activeAtOffset = reader.int64().toBigInt();
          break;
        case /* com.daml.ledger.api.v2.EventFormat event_format */
        4:
          message.eventFormat = EventFormat.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.eventFormat
          );
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.filter)
      TransactionFilter.internalBinaryWrite(
        message.filter,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.verbose !== false)
      writer.tag(2, WireType.Varint).bool(message.verbose);
    if (message.activeAtOffset !== 0n)
      writer.tag(3, WireType.Varint).int64(message.activeAtOffset);
    if (message.eventFormat)
      EventFormat.internalBinaryWrite(
        message.eventFormat,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetActiveContractsRequest = new GetActiveContractsRequest$Type();
class GetActiveContractsResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetActiveContractsResponse", [
      {
        no: 1,
        name: "workflow_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "active_contract",
        kind: "message",
        oneof: "contractEntry",
        T: () => ActiveContract
      },
      {
        no: 3,
        name: "incomplete_unassigned",
        kind: "message",
        oneof: "contractEntry",
        T: () => IncompleteUnassigned
      },
      {
        no: 4,
        name: "incomplete_assigned",
        kind: "message",
        oneof: "contractEntry",
        T: () => IncompleteAssigned
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.workflowId = "";
    message.contractEntry = { oneofKind: void 0 };
    if (value !== void 0)
      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 workflow_id */
        1:
          message.workflowId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.ActiveContract active_contract */
        2:
          message.contractEntry = {
            oneofKind: "activeContract",
            activeContract: ActiveContract.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.contractEntry.activeContract
            )
          };
          break;
        case /* com.daml.ledger.api.v2.IncompleteUnassigned incomplete_unassigned */
        3:
          message.contractEntry = {
            oneofKind: "incompleteUnassigned",
            incompleteUnassigned: IncompleteUnassigned.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.contractEntry.incompleteUnassigned
            )
          };
          break;
        case /* com.daml.ledger.api.v2.IncompleteAssigned incomplete_assigned */
        4:
          message.contractEntry = {
            oneofKind: "incompleteAssigned",
            incompleteAssigned: IncompleteAssigned.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.contractEntry.incompleteAssigned
            )
          };
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.workflowId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.workflowId);
    if (message.contractEntry.oneofKind === "activeContract")
      ActiveContract.internalBinaryWrite(
        message.contractEntry.activeContract,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.contractEntry.oneofKind === "incompleteUnassigned")
      IncompleteUnassigned.internalBinaryWrite(
        message.contractEntry.incompleteUnassigned,
        writer.tag(3, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.contractEntry.oneofKind === "incompleteAssigned")
      IncompleteAssigned.internalBinaryWrite(
        message.contractEntry.incompleteAssigned,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetActiveContractsResponse = new GetActiveContractsResponse$Type();
class ActiveContract$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ActiveContract", [
      {
        no: 1,
        name: "created_event",
        kind: "message",
        T: () => CreatedEvent
      },
      {
        no: 2,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "reassignment_counter",
        kind: "scalar",
        T: 4,
        L: 0
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.synchronizerId = "";
    message.reassignmentCounter = 0n;
    if (value !== void 0)
      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_event */
        1:
          message.createdEvent = CreatedEvent.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.createdEvent
          );
          break;
        case /* string synchronizer_id */
        2:
          message.synchronizerId = reader.string();
          break;
        case /* uint64 reassignment_counter */
        3:
          message.reassignmentCounter = reader.uint64().toBigInt();
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.createdEvent)
      CreatedEvent.internalBinaryWrite(
        message.createdEvent,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.synchronizerId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.synchronizerId);
    if (message.reassignmentCounter !== 0n)
      writer.tag(3, WireType.Varint).uint64(message.reassignmentCounter);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const ActiveContract = new ActiveContract$Type();
class IncompleteUnassigned$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.IncompleteUnassigned", [
      {
        no: 1,
        name: "created_event",
        kind: "message",
        T: () => CreatedEvent
      },
      {
        no: 2,
        name: "unassigned_event",
        kind: "message",
        T: () => UnassignedEvent
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    if (value !== void 0)
      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_event */
        1:
          message.createdEvent = CreatedEvent.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.createdEvent
          );
          break;
        case /* com.daml.ledger.api.v2.UnassignedEvent unassigned_event */
        2:
          message.unassignedEvent = UnassignedEvent.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.unassignedEvent
          );
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.createdEvent)
      CreatedEvent.internalBinaryWrite(
        message.createdEvent,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.unassignedEvent)
      UnassignedEvent.internalBinaryWrite(
        message.unassignedEvent,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const IncompleteUnassigned = new IncompleteUnassigned$Type();
class IncompleteAssigned$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.IncompleteAssigned", [
      {
        no: 1,
        name: "assigned_event",
        kind: "message",
        T: () => AssignedEvent
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    if (value !== void 0)
      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.AssignedEvent assigned_event */
        1:
          message.assignedEvent = AssignedEvent.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.assignedEvent
          );
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.assignedEvent)
      AssignedEvent.internalBinaryWrite(
        message.assignedEvent,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const IncompleteAssigned = new IncompleteAssigned$Type();
class GetConnectedSynchronizersRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetConnectedSynchronizersRequest", [
      {
        no: 1,
        name: "party",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "participant_id",
        kind: "scalar",
        T: 9
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.party = "";
    message.participantId = "";
    if (value !== void 0)
      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 party */
        1:
          message.party = reader.string();
          break;
        case /* string participant_id */
        2:
          message.participantId = reader.string();
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.party !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.party);
    if (message.participantId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.participantId);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetConnectedSynchronizersRequest = new GetConnectedSynchronizersRequest$Type();
class GetConnectedSynchronizersResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetConnectedSynchronizersResponse", [
      {
        no: 1,
        name: "connected_synchronizers",
        kind: "message",
        repeat: 2,
        T: () => GetConnectedSynchronizersResponse_ConnectedSynchronizer
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.connectedSynchronizers = [];
    if (value !== void 0)
      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 /* repeated com.daml.ledger.api.v2.GetConnectedSynchronizersResponse.ConnectedSynchronizer connected_synchronizers */
        1:
          message.connectedSynchronizers.push(
            GetConnectedSynchronizersResponse_ConnectedSynchronizer.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    for (let i = 0; i < message.connectedSynchronizers.length; i++)
      GetConnectedSynchronizersResponse_ConnectedSynchronizer.internalBinaryWrite(
        message.connectedSynchronizers[i],
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetConnectedSynchronizersResponse = new GetConnectedSynchronizersResponse$Type();
class GetConnectedSynchronizersResponse_ConnectedSynchronizer$Type extends MessageType {
  constructor() {
    super(
      "com.daml.ledger.api.v2.GetConnectedSynchronizersResponse.ConnectedSynchronizer",
      [
        {
          no: 1,
          name: "synchronizer_alias",
          kind: "scalar",
          T: 9
        },
        {
          no: 2,
          name: "synchronizer_id",
          kind: "scalar",
          T: 9
        },
        {
          no: 3,
          name: "permission",
          kind: "enum",
          T: () => [
            "com.daml.ledger.api.v2.ParticipantPermission",
            ParticipantPermission,
            "PARTICIPANT_PERMISSION_"
          ]
        }
      ]
    );
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.synchronizerAlias = "";
    message.synchronizerId = "";
    message.permission = 0;
    if (value !== void 0)
      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 synchronizer_alias */
        1:
          message.synchronizerAlias = reader.string();
          break;
        case /* string synchronizer_id */
        2:
          message.synchronizerId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.ParticipantPermission permission */
        3:
          message.permission = reader.int32();
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.synchronizerAlias !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.synchronizerAlias);
    if (message.synchronizerId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.synchronizerId);
    if (message.permission !== 0)
      writer.tag(3, WireType.Varint).int32(message.permission);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetConnectedSynchronizersResponse_ConnectedSynchronizer = new GetConnectedSynchronizersResponse_ConnectedSynchronizer$Type();
class GetLedgerEndRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetLedgerEndRequest", []);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    if (value !== void 0)
      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) {
        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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetLedgerEndRequest = new GetLedgerEndRequest$Type();
class GetLedgerEndResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetLedgerEndResponse", [
      {
        no: 1,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.offset = 0n;
    if (value !== void 0)
      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 /* int64 offset */
        1:
          message.offset = reader.int64().toBigInt();
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.offset !== 0n)
      writer.tag(1, WireType.Varint).int64(message.offset);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetLedgerEndResponse = new GetLedgerEndResponse$Type();
class GetLatestPrunedOffsetsRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetLatestPrunedOffsetsRequest", []);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    if (value !== void 0)
      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) {
        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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetLatestPrunedOffsetsRequest = new GetLatestPrunedOffsetsRequest$Type();
class GetLatestPrunedOffsetsResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetLatestPrunedOffsetsResponse", [
      {
        no: 1,
        name: "participant_pruned_up_to_inclusive",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 2,
        name: "all_divulged_contracts_pruned_up_to_inclusive",
        kind: "scalar",
        T: 3,
        L: 0
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.participantPrunedUpToInclusive = 0n;
    message.allDivulgedContractsPrunedUpToInclusive = 0n;
    if (value !== void 0)
      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 /* int64 participant_pruned_up_to_inclusive */
        1:
          message.participantPrunedUpToInclusive = reader.int64().toBigInt();
          break;
        case /* int64 all_divulged_contracts_pruned_up_to_inclusive */
        2:
          message.allDivulgedContractsPrunedUpToInclusive = reader.int64().toBigInt();
          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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.participantPrunedUpToInclusive !== 0n)
      writer.tag(1, WireType.Varint).int64(message.participantPrunedUpToInclusive);
    if (message.allDivulgedContractsPrunedUpToInclusive !== 0n)
      writer.tag(2, WireType.Varint).int64(message.allDivulgedContractsPrunedUpToInclusive);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetLatestPrunedOffsetsResponse = new GetLatestPrunedOffsetsResponse$Type();
const StateService = new ServiceType(
  "com.daml.ledger.api.v2.StateService",
  [
    {
      name: "GetActiveContracts",
      serverStreaming: true,
      options: {},
      I: GetActiveContractsRequest,
      O: GetActiveContractsResponse
    },
    {
      name: "GetConnectedSynchronizers",
      options: {},
      I: GetConnectedSynchronizersRequest,
      O: GetConnectedSynchronizersResponse
    },
    {
      name: "GetLedgerEnd",
      options: {},
      I: GetLedgerEndRequest,
      O: GetLedgerEndResponse
    },
    {
      name: "GetLatestPrunedOffsets",
      options: {},
      I: GetLatestPrunedOffsetsRequest,
      O: GetLatestPrunedOffsetsResponse
    }
  ]
);
export {
  ActiveContract,
  GetActiveContractsRequest,
  GetActiveContractsResponse,
  GetConnectedSynchronizersRequest,
  GetConnectedSynchronizersResponse,
  GetConnectedSynchronizersResponse_ConnectedSynchronizer,
  GetLatestPrunedOffsetsRequest,
  GetLatestPrunedOffsetsResponse,
  GetLedgerEndRequest,
  GetLedgerEndResponse,
  IncompleteAssigned,
  IncompleteUnassigned,
  ParticipantPermission,
  StateService
};
//# sourceMappingURL=state_service.js.map