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 { ArchivedEvent } from "./event.js";
import { CreatedEvent } from "./event.js";
import { EventFormat } from "./transaction_filter.js";
class GetEventsByContractIdRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetEventsByContractIdRequest", [
      {
        no: 1,
        name: "contract_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "requesting_parties",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 3,
        name: "event_format",
        kind: "message",
        T: () => EventFormat
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.contractId = "";
    message.requestingParties = [];
    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 contract_id */
        1:
          message.contractId = reader.string();
          break;
        case /* repeated string requesting_parties = 2 [deprecated = true] */
        2:
          message.requestingParties.push(reader.string());
          break;
        case /* com.daml.ledger.api.v2.EventFormat event_format */
        3:
          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.contractId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.contractId);
    for (let i = 0; i < message.requestingParties.length; i++)
      writer.tag(2, WireType.LengthDelimited).string(message.requestingParties[i]);
    if (message.eventFormat)
      EventFormat.internalBinaryWrite(
        message.eventFormat,
        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 GetEventsByContractIdRequest = new GetEventsByContractIdRequest$Type();
class GetEventsByContractIdResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.GetEventsByContractIdResponse", [
      { no: 1, name: "created", kind: "message", T: () => Created },
      { no: 2, name: "archived", kind: "message", T: () => Archived }
    ]);
  }
  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.Created created */
        1:
          message.created = Created.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.created
          );
          break;
        case /* com.daml.ledger.api.v2.Archived archived */
        2:
          message.archived = Archived.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.archived
          );
          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.created)
      Created.internalBinaryWrite(
        message.created,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.archived)
      Archived.internalBinaryWrite(
        message.archived,
        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 GetEventsByContractIdResponse = new GetEventsByContractIdResponse$Type();
class Created$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.Created", [
      {
        no: 1,
        name: "created_event",
        kind: "message",
        T: () => CreatedEvent
      },
      {
        no: 2,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.synchronizerId = "";
    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;
        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);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const Created = new Created$Type();
class Archived$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.Archived", [
      {
        no: 1,
        name: "archived_event",
        kind: "message",
        T: () => ArchivedEvent
      },
      {
        no: 2,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.synchronizerId = "";
    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.ArchivedEvent archived_event */
        1:
          message.archivedEvent = ArchivedEvent.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.archivedEvent
          );
          break;
        case /* string synchronizer_id */
        2:
          message.synchronizerId = 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.archivedEvent)
      ArchivedEvent.internalBinaryWrite(
        message.archivedEvent,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.synchronizerId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.synchronizerId);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const Archived = new Archived$Type();
const EventQueryService = new ServiceType(
  "com.daml.ledger.api.v2.EventQueryService",
  [
    {
      name: "GetEventsByContractId",
      options: {},
      I: GetEventsByContractIdRequest,
      O: GetEventsByContractIdResponse
    }
  ]
);
export {
  Archived,
  Created,
  EventQueryService,
  GetEventsByContractIdRequest,
  GetEventsByContractIdResponse
};
//# sourceMappingURL=event_query_service.js.map