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 { OffsetCheckpoint } from "./offset_checkpoint.js";
import { Completion } from "./completion.js";
class CompletionStreamRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.CompletionStreamRequest", [
      {
        no: 1,
        name: "user_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "parties",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 3,
        name: "begin_exclusive",
        kind: "scalar",
        T: 3,
        L: 0
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.userId = "";
    message.parties = [];
    message.beginExclusive = 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 /* string user_id */
        1:
          message.userId = reader.string();
          break;
        case /* repeated string parties */
        2:
          message.parties.push(reader.string());
          break;
        case /* int64 begin_exclusive */
        3:
          message.beginExclusive = 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.userId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.userId);
    for (let i = 0; i < message.parties.length; i++)
      writer.tag(2, WireType.LengthDelimited).string(message.parties[i]);
    if (message.beginExclusive !== 0n)
      writer.tag(3, WireType.Varint).int64(message.beginExclusive);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const CompletionStreamRequest = new CompletionStreamRequest$Type();
class CompletionStreamResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.CompletionStreamResponse", [
      {
        no: 1,
        name: "completion",
        kind: "message",
        oneof: "completionResponse",
        T: () => Completion
      },
      {
        no: 2,
        name: "offset_checkpoint",
        kind: "message",
        oneof: "completionResponse",
        T: () => OffsetCheckpoint
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.completionResponse = { 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.Completion completion */
        1:
          message.completionResponse = {
            oneofKind: "completion",
            completion: Completion.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.completionResponse.completion
            )
          };
          break;
        case /* com.daml.ledger.api.v2.OffsetCheckpoint offset_checkpoint */
        2:
          message.completionResponse = {
            oneofKind: "offsetCheckpoint",
            offsetCheckpoint: OffsetCheckpoint.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.completionResponse.offsetCheckpoint
            )
          };
          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.completionResponse.oneofKind === "completion")
      Completion.internalBinaryWrite(
        message.completionResponse.completion,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.completionResponse.oneofKind === "offsetCheckpoint")
      OffsetCheckpoint.internalBinaryWrite(
        message.completionResponse.offsetCheckpoint,
        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 CompletionStreamResponse = new CompletionStreamResponse$Type();
const CommandCompletionService = new ServiceType(
  "com.daml.ledger.api.v2.CommandCompletionService",
  [
    {
      name: "CompletionStream",
      serverStreaming: true,
      options: {},
      I: CompletionStreamRequest,
      O: CompletionStreamResponse
    }
  ]
);
export {
  CommandCompletionService,
  CompletionStreamRequest,
  CompletionStreamResponse
};
//# sourceMappingURL=command_completion_service.js.map