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 { Status } from "../../../../../google/rpc/status.js";
import { Timestamp } from "../../../../../google/protobuf/timestamp.js";
import { Record } from "./value.js";
import { Value } from "./value.js";
import { Identifier } from "./value.js";
class Event$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.Event", [
      {
        no: 1,
        name: "created",
        kind: "message",
        oneof: "event",
        T: () => CreatedEvent
      },
      {
        no: 2,
        name: "archived",
        kind: "message",
        oneof: "event",
        T: () => ArchivedEvent
      },
      {
        no: 3,
        name: "exercised",
        kind: "message",
        oneof: "event",
        T: () => ExercisedEvent
      }
    ]);
  }
  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.CreatedEvent created */
        1:
          message.event = {
            oneofKind: "created",
            created: CreatedEvent.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.event.created
            )
          };
          break;
        case /* com.daml.ledger.api.v2.ArchivedEvent archived */
        2:
          message.event = {
            oneofKind: "archived",
            archived: ArchivedEvent.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.event.archived
            )
          };
          break;
        case /* com.daml.ledger.api.v2.ExercisedEvent exercised */
        3:
          message.event = {
            oneofKind: "exercised",
            exercised: ExercisedEvent.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.event.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 ? UnknownFieldHandler.onRead : u)(
              this.typeName,
              message,
              fieldNo,
              wireType,
              d
            );
      }
    }
    return message;
  }
  internalBinaryWrite(message, writer, options) {
    if (message.event.oneofKind === "created")
      CreatedEvent.internalBinaryWrite(
        message.event.created,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.event.oneofKind === "archived")
      ArchivedEvent.internalBinaryWrite(
        message.event.archived,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.event.oneofKind === "exercised")
      ExercisedEvent.internalBinaryWrite(
        message.event.exercised,
        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 Event = new Event$Type();
class CreatedEvent$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.CreatedEvent", [
      {
        no: 1,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 2,
        name: "node_id",
        kind: "scalar",
        T: 5
      },
      {
        no: 3,
        name: "contract_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 4,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      { no: 5, name: "contract_key", kind: "message", T: () => Value },
      {
        no: 6,
        name: "create_arguments",
        kind: "message",
        T: () => Record
      },
      {
        no: 7,
        name: "created_event_blob",
        kind: "scalar",
        T: 12
      },
      {
        no: 8,
        name: "interface_views",
        kind: "message",
        repeat: 2,
        T: () => InterfaceView
      },
      {
        no: 9,
        name: "witness_parties",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 10,
        name: "signatories",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 11,
        name: "observers",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      { no: 12, name: "created_at", kind: "message", T: () => Timestamp },
      {
        no: 13,
        name: "package_name",
        kind: "scalar",
        T: 9
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.offset = 0n;
    message.nodeId = 0;
    message.contractId = "";
    message.createdEventBlob = new Uint8Array(0);
    message.interfaceViews = [];
    message.witnessParties = [];
    message.signatories = [];
    message.observers = [];
    message.packageName = "";
    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;
        case /* int32 node_id */
        2:
          message.nodeId = reader.int32();
          break;
        case /* string contract_id */
        3:
          message.contractId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.Identifier template_id */
        4:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* com.daml.ledger.api.v2.Value contract_key */
        5:
          message.contractKey = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.contractKey
          );
          break;
        case /* com.daml.ledger.api.v2.Record create_arguments */
        6:
          message.createArguments = Record.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.createArguments
          );
          break;
        case /* bytes created_event_blob */
        7:
          message.createdEventBlob = reader.bytes();
          break;
        case /* repeated com.daml.ledger.api.v2.InterfaceView interface_views */
        8:
          message.interfaceViews.push(
            InterfaceView.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* repeated string witness_parties */
        9:
          message.witnessParties.push(reader.string());
          break;
        case /* repeated string signatories */
        10:
          message.signatories.push(reader.string());
          break;
        case /* repeated string observers */
        11:
          message.observers.push(reader.string());
          break;
        case /* google.protobuf.Timestamp created_at */
        12:
          message.createdAt = Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.createdAt
          );
          break;
        case /* string package_name */
        13:
          message.packageName = 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.offset !== 0n)
      writer.tag(1, WireType.Varint).int64(message.offset);
    if (message.nodeId !== 0)
      writer.tag(2, WireType.Varint).int32(message.nodeId);
    if (message.contractId !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.contractId);
    if (message.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.contractKey)
      Value.internalBinaryWrite(
        message.contractKey,
        writer.tag(5, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.createArguments)
      Record.internalBinaryWrite(
        message.createArguments,
        writer.tag(6, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.createdEventBlob.length)
      writer.tag(7, WireType.LengthDelimited).bytes(message.createdEventBlob);
    for (let i = 0; i < message.interfaceViews.length; i++)
      InterfaceView.internalBinaryWrite(
        message.interfaceViews[i],
        writer.tag(8, WireType.LengthDelimited).fork(),
        options
      ).join();
    for (let i = 0; i < message.witnessParties.length; i++)
      writer.tag(9, WireType.LengthDelimited).string(message.witnessParties[i]);
    for (let i = 0; i < message.signatories.length; i++)
      writer.tag(10, WireType.LengthDelimited).string(message.signatories[i]);
    for (let i = 0; i < message.observers.length; i++)
      writer.tag(11, WireType.LengthDelimited).string(message.observers[i]);
    if (message.createdAt)
      Timestamp.internalBinaryWrite(
        message.createdAt,
        writer.tag(12, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.packageName !== "")
      writer.tag(13, WireType.LengthDelimited).string(message.packageName);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const CreatedEvent = new CreatedEvent$Type();
class InterfaceView$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.InterfaceView", [
      {
        no: 1,
        name: "interface_id",
        kind: "message",
        T: () => Identifier
      },
      { no: 2, name: "view_status", kind: "message", T: () => Status },
      { no: 3, name: "view_value", kind: "message", T: () => Record }
    ]);
  }
  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.Identifier interface_id */
        1:
          message.interfaceId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.interfaceId
          );
          break;
        case /* google.rpc.Status view_status */
        2:
          message.viewStatus = Status.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.viewStatus
          );
          break;
        case /* com.daml.ledger.api.v2.Record view_value */
        3:
          message.viewValue = Record.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.viewValue
          );
          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.interfaceId)
      Identifier.internalBinaryWrite(
        message.interfaceId,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.viewStatus)
      Status.internalBinaryWrite(
        message.viewStatus,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.viewValue)
      Record.internalBinaryWrite(
        message.viewValue,
        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 InterfaceView = new InterfaceView$Type();
class ArchivedEvent$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ArchivedEvent", [
      {
        no: 1,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 2,
        name: "node_id",
        kind: "scalar",
        T: 5
      },
      {
        no: 3,
        name: "contract_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 4,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 5,
        name: "witness_parties",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 6,
        name: "package_name",
        kind: "scalar",
        T: 9
      },
      {
        no: 7,
        name: "implemented_interfaces",
        kind: "message",
        repeat: 2,
        T: () => Identifier
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.offset = 0n;
    message.nodeId = 0;
    message.contractId = "";
    message.witnessParties = [];
    message.packageName = "";
    message.implementedInterfaces = [];
    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;
        case /* int32 node_id */
        2:
          message.nodeId = reader.int32();
          break;
        case /* string contract_id */
        3:
          message.contractId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.Identifier template_id */
        4:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* repeated string witness_parties */
        5:
          message.witnessParties.push(reader.string());
          break;
        case /* string package_name */
        6:
          message.packageName = reader.string();
          break;
        case /* repeated com.daml.ledger.api.v2.Identifier implemented_interfaces */
        7:
          message.implementedInterfaces.push(
            Identifier.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) {
    if (message.offset !== 0n)
      writer.tag(1, WireType.Varint).int64(message.offset);
    if (message.nodeId !== 0)
      writer.tag(2, WireType.Varint).int32(message.nodeId);
    if (message.contractId !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.contractId);
    if (message.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    for (let i = 0; i < message.witnessParties.length; i++)
      writer.tag(5, WireType.LengthDelimited).string(message.witnessParties[i]);
    if (message.packageName !== "")
      writer.tag(6, WireType.LengthDelimited).string(message.packageName);
    for (let i = 0; i < message.implementedInterfaces.length; i++)
      Identifier.internalBinaryWrite(
        message.implementedInterfaces[i],
        writer.tag(7, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const ArchivedEvent = new ArchivedEvent$Type();
class ExercisedEvent$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ExercisedEvent", [
      {
        no: 1,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 2,
        name: "node_id",
        kind: "scalar",
        T: 5
      },
      {
        no: 3,
        name: "contract_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 4,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 5,
        name: "interface_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 6,
        name: "choice",
        kind: "scalar",
        T: 9
      },
      { no: 7, name: "choice_argument", kind: "message", T: () => Value },
      {
        no: 8,
        name: "acting_parties",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 9,
        name: "consuming",
        kind: "scalar",
        T: 8
      },
      {
        no: 10,
        name: "witness_parties",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 11,
        name: "last_descendant_node_id",
        kind: "scalar",
        T: 5
      },
      {
        no: 12,
        name: "exercise_result",
        kind: "message",
        T: () => Value
      },
      {
        no: 13,
        name: "package_name",
        kind: "scalar",
        T: 9
      },
      {
        no: 14,
        name: "implemented_interfaces",
        kind: "message",
        repeat: 2,
        T: () => Identifier
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.offset = 0n;
    message.nodeId = 0;
    message.contractId = "";
    message.choice = "";
    message.actingParties = [];
    message.consuming = false;
    message.witnessParties = [];
    message.lastDescendantNodeId = 0;
    message.packageName = "";
    message.implementedInterfaces = [];
    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;
        case /* int32 node_id */
        2:
          message.nodeId = reader.int32();
          break;
        case /* string contract_id */
        3:
          message.contractId = reader.string();
          break;
        case /* com.daml.ledger.api.v2.Identifier template_id */
        4:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* com.daml.ledger.api.v2.Identifier interface_id */
        5:
          message.interfaceId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.interfaceId
          );
          break;
        case /* string choice */
        6:
          message.choice = reader.string();
          break;
        case /* com.daml.ledger.api.v2.Value choice_argument */
        7:
          message.choiceArgument = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.choiceArgument
          );
          break;
        case /* repeated string acting_parties */
        8:
          message.actingParties.push(reader.string());
          break;
        case /* bool consuming */
        9:
          message.consuming = reader.bool();
          break;
        case /* repeated string witness_parties */
        10:
          message.witnessParties.push(reader.string());
          break;
        case /* int32 last_descendant_node_id */
        11:
          message.lastDescendantNodeId = reader.int32();
          break;
        case /* com.daml.ledger.api.v2.Value exercise_result */
        12:
          message.exerciseResult = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.exerciseResult
          );
          break;
        case /* string package_name */
        13:
          message.packageName = reader.string();
          break;
        case /* repeated com.daml.ledger.api.v2.Identifier implemented_interfaces */
        14:
          message.implementedInterfaces.push(
            Identifier.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) {
    if (message.offset !== 0n)
      writer.tag(1, WireType.Varint).int64(message.offset);
    if (message.nodeId !== 0)
      writer.tag(2, WireType.Varint).int32(message.nodeId);
    if (message.contractId !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.contractId);
    if (message.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.interfaceId)
      Identifier.internalBinaryWrite(
        message.interfaceId,
        writer.tag(5, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.choice !== "")
      writer.tag(6, WireType.LengthDelimited).string(message.choice);
    if (message.choiceArgument)
      Value.internalBinaryWrite(
        message.choiceArgument,
        writer.tag(7, WireType.LengthDelimited).fork(),
        options
      ).join();
    for (let i = 0; i < message.actingParties.length; i++)
      writer.tag(8, WireType.LengthDelimited).string(message.actingParties[i]);
    if (message.consuming !== false)
      writer.tag(9, WireType.Varint).bool(message.consuming);
    for (let i = 0; i < message.witnessParties.length; i++)
      writer.tag(10, WireType.LengthDelimited).string(message.witnessParties[i]);
    if (message.lastDescendantNodeId !== 0)
      writer.tag(11, WireType.Varint).int32(message.lastDescendantNodeId);
    if (message.exerciseResult)
      Value.internalBinaryWrite(
        message.exerciseResult,
        writer.tag(12, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.packageName !== "")
      writer.tag(13, WireType.LengthDelimited).string(message.packageName);
    for (let i = 0; i < message.implementedInterfaces.length; i++)
      Identifier.internalBinaryWrite(
        message.implementedInterfaces[i],
        writer.tag(14, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const ExercisedEvent = new ExercisedEvent$Type();
export {
  ArchivedEvent,
  CreatedEvent,
  Event,
  ExercisedEvent,
  InterfaceView
};
//# sourceMappingURL=event.js.map