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 { SynchronizerTime } from "./offset_checkpoint.js";
import { TraceContext } from "./trace_context.js";
import { Duration } from "../../../../../google/protobuf/duration.js";
import { Status } from "../../../../../google/rpc/status.js";
class Completion$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.Completion", [
      {
        no: 1,
        name: "command_id",
        kind: "scalar",
        T: 9
      },
      { no: 2, name: "status", kind: "message", T: () => Status },
      {
        no: 3,
        name: "update_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 4,
        name: "user_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 5,
        name: "act_as",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 6,
        name: "submission_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 7,
        name: "deduplication_offset",
        kind: "scalar",
        oneof: "deduplicationPeriod",
        T: 3,
        L: 0
      },
      {
        no: 8,
        name: "deduplication_duration",
        kind: "message",
        oneof: "deduplicationPeriod",
        T: () => Duration
      },
      {
        no: 9,
        name: "trace_context",
        kind: "message",
        T: () => TraceContext
      },
      {
        no: 10,
        name: "offset",
        kind: "scalar",
        T: 3,
        L: 0
      },
      {
        no: 11,
        name: "synchronizer_time",
        kind: "message",
        T: () => SynchronizerTime
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.commandId = "";
    message.updateId = "";
    message.userId = "";
    message.actAs = [];
    message.submissionId = "";
    message.deduplicationPeriod = { oneofKind: void 0 };
    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 /* string command_id */
        1:
          message.commandId = reader.string();
          break;
        case /* google.rpc.Status status */
        2:
          message.status = Status.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.status
          );
          break;
        case /* string update_id */
        3:
          message.updateId = reader.string();
          break;
        case /* string user_id */
        4:
          message.userId = reader.string();
          break;
        case /* repeated string act_as */
        5:
          message.actAs.push(reader.string());
          break;
        case /* string submission_id */
        6:
          message.submissionId = reader.string();
          break;
        case /* int64 deduplication_offset */
        7:
          message.deduplicationPeriod = {
            oneofKind: "deduplicationOffset",
            deduplicationOffset: reader.int64().toBigInt()
          };
          break;
        case /* google.protobuf.Duration deduplication_duration */
        8:
          message.deduplicationPeriod = {
            oneofKind: "deduplicationDuration",
            deduplicationDuration: Duration.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.deduplicationPeriod.deduplicationDuration
            )
          };
          break;
        case /* com.daml.ledger.api.v2.TraceContext trace_context */
        9:
          message.traceContext = TraceContext.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.traceContext
          );
          break;
        case /* int64 offset */
        10:
          message.offset = reader.int64().toBigInt();
          break;
        case /* com.daml.ledger.api.v2.SynchronizerTime synchronizer_time */
        11:
          message.synchronizerTime = SynchronizerTime.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.synchronizerTime
          );
          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.commandId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.commandId);
    if (message.status)
      Status.internalBinaryWrite(
        message.status,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.updateId !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.updateId);
    if (message.userId !== "")
      writer.tag(4, WireType.LengthDelimited).string(message.userId);
    for (let i = 0; i < message.actAs.length; i++)
      writer.tag(5, WireType.LengthDelimited).string(message.actAs[i]);
    if (message.submissionId !== "")
      writer.tag(6, WireType.LengthDelimited).string(message.submissionId);
    if (message.deduplicationPeriod.oneofKind === "deduplicationOffset")
      writer.tag(7, WireType.Varint).int64(message.deduplicationPeriod.deduplicationOffset);
    if (message.deduplicationPeriod.oneofKind === "deduplicationDuration")
      Duration.internalBinaryWrite(
        message.deduplicationPeriod.deduplicationDuration,
        writer.tag(8, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.traceContext)
      TraceContext.internalBinaryWrite(
        message.traceContext,
        writer.tag(9, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.offset !== 0n)
      writer.tag(10, WireType.Varint).int64(message.offset);
    if (message.synchronizerTime)
      SynchronizerTime.internalBinaryWrite(
        message.synchronizerTime,
        writer.tag(11, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const Completion = new Completion$Type();
export {
  Completion
};
//# sourceMappingURL=completion.js.map