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 { ParticipantPermission } from "./state_service.js";
import { TraceContext } from "./trace_context.js";
import { Timestamp } from "../../../../../google/protobuf/timestamp.js";
class TopologyTransaction$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.TopologyTransaction", [
      {
        no: 1,
        name: "update_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 3,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      },
      { no: 4, name: "record_time", kind: "message", T: () => Timestamp },
      {
        no: 5,
        name: "events",
        kind: "message",
        repeat: 2,
        T: () => TopologyEvent
      },
      {
        no: 6,
        name: "trace_context",
        kind: "message",
        T: () => TraceContext
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.updateId = "";
    message.offset = 0n;
    message.synchronizerId = "";
    message.events = [];
    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 update_id */
        1:
          message.updateId = reader.string();
          break;
        case /* int64 offset */
        2:
          message.offset = reader.int64().toBigInt();
          break;
        case /* string synchronizer_id */
        3:
          message.synchronizerId = reader.string();
          break;
        case /* google.protobuf.Timestamp record_time */
        4:
          message.recordTime = Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.recordTime
          );
          break;
        case /* repeated com.daml.ledger.api.v2.TopologyEvent events */
        5:
          message.events.push(
            TopologyEvent.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* com.daml.ledger.api.v2.TraceContext trace_context */
        6:
          message.traceContext = TraceContext.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.traceContext
          );
          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.updateId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.updateId);
    if (message.offset !== 0n)
      writer.tag(2, WireType.Varint).int64(message.offset);
    if (message.synchronizerId !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.synchronizerId);
    if (message.recordTime)
      Timestamp.internalBinaryWrite(
        message.recordTime,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    for (let i = 0; i < message.events.length; i++)
      TopologyEvent.internalBinaryWrite(
        message.events[i],
        writer.tag(5, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.traceContext)
      TraceContext.internalBinaryWrite(
        message.traceContext,
        writer.tag(6, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const TopologyTransaction = new TopologyTransaction$Type();
class TopologyEvent$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.TopologyEvent", [
      {
        no: 1,
        name: "participant_authorization_changed",
        kind: "message",
        oneof: "event",
        T: () => ParticipantAuthorizationChanged
      },
      {
        no: 2,
        name: "participant_authorization_revoked",
        kind: "message",
        oneof: "event",
        T: () => ParticipantAuthorizationRevoked
      },
      {
        no: 3,
        name: "participant_authorization_added",
        kind: "message",
        oneof: "event",
        T: () => ParticipantAuthorizationAdded
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.event = { 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 /* com.daml.ledger.api.v2.ParticipantAuthorizationChanged participant_authorization_changed */
        1:
          message.event = {
            oneofKind: "participantAuthorizationChanged",
            participantAuthorizationChanged: ParticipantAuthorizationChanged.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.event.participantAuthorizationChanged
            )
          };
          break;
        case /* com.daml.ledger.api.v2.ParticipantAuthorizationRevoked participant_authorization_revoked */
        2:
          message.event = {
            oneofKind: "participantAuthorizationRevoked",
            participantAuthorizationRevoked: ParticipantAuthorizationRevoked.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.event.participantAuthorizationRevoked
            )
          };
          break;
        case /* com.daml.ledger.api.v2.ParticipantAuthorizationAdded participant_authorization_added */
        3:
          message.event = {
            oneofKind: "participantAuthorizationAdded",
            participantAuthorizationAdded: ParticipantAuthorizationAdded.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.event.participantAuthorizationAdded
            )
          };
          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.event.oneofKind === "participantAuthorizationChanged")
      ParticipantAuthorizationChanged.internalBinaryWrite(
        message.event.participantAuthorizationChanged,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.event.oneofKind === "participantAuthorizationRevoked")
      ParticipantAuthorizationRevoked.internalBinaryWrite(
        message.event.participantAuthorizationRevoked,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.event.oneofKind === "participantAuthorizationAdded")
      ParticipantAuthorizationAdded.internalBinaryWrite(
        message.event.participantAuthorizationAdded,
        writer.tag(3, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const TopologyEvent = new TopologyEvent$Type();
class ParticipantAuthorizationAdded$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ParticipantAuthorizationAdded", [
      {
        no: 1,
        name: "party_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "participant_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "participant_permission",
        kind: "enum",
        T: () => [
          "com.daml.ledger.api.v2.ParticipantPermission",
          ParticipantPermission,
          "PARTICIPANT_PERMISSION_"
        ]
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.partyId = "";
    message.participantId = "";
    message.participantPermission = 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 party_id */
        1:
          message.partyId = reader.string();
          break;
        case /* string participant_id */
        2:
          message.participantId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.ParticipantPermission participant_permission */
        3:
          message.participantPermission = 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.partyId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.partyId);
    if (message.participantId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.participantId);
    if (message.participantPermission !== 0)
      writer.tag(3, WireType.Varint).int32(message.participantPermission);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const ParticipantAuthorizationAdded = new ParticipantAuthorizationAdded$Type();
class ParticipantAuthorizationChanged$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ParticipantAuthorizationChanged", [
      {
        no: 1,
        name: "party_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "participant_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "participant_permission",
        kind: "enum",
        T: () => [
          "com.daml.ledger.api.v2.ParticipantPermission",
          ParticipantPermission,
          "PARTICIPANT_PERMISSION_"
        ]
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.partyId = "";
    message.participantId = "";
    message.participantPermission = 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 party_id */
        1:
          message.partyId = reader.string();
          break;
        case /* string participant_id */
        2:
          message.participantId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.ParticipantPermission participant_permission */
        3:
          message.participantPermission = 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.partyId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.partyId);
    if (message.participantId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.participantId);
    if (message.participantPermission !== 0)
      writer.tag(3, WireType.Varint).int32(message.participantPermission);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const ParticipantAuthorizationChanged = new ParticipantAuthorizationChanged$Type();
class ParticipantAuthorizationRevoked$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ParticipantAuthorizationRevoked", [
      {
        no: 1,
        name: "party_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "participant_id",
        kind: "scalar",
        T: 9
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.partyId = "";
    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_id */
        1:
          message.partyId = 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.partyId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.partyId);
    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 ParticipantAuthorizationRevoked = new ParticipantAuthorizationRevoked$Type();
export {
  ParticipantAuthorizationAdded,
  ParticipantAuthorizationChanged,
  ParticipantAuthorizationRevoked,
  TopologyEvent,
  TopologyTransaction
};
//# sourceMappingURL=topology_transaction.js.map