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 { Timestamp } from "../../../../../google/protobuf/timestamp.js";
import { Duration } from "../../../../../google/protobuf/duration.js";
import { Value } from "./value.js";
import { Record } from "./value.js";
import { Identifier } from "./value.js";
class Command$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.Command", [
      {
        no: 1,
        name: "create",
        kind: "message",
        oneof: "command",
        T: () => CreateCommand
      },
      {
        no: 2,
        name: "exercise",
        kind: "message",
        oneof: "command",
        T: () => ExerciseCommand
      },
      {
        no: 4,
        name: "exercise_by_key",
        kind: "message",
        oneof: "command",
        T: () => ExerciseByKeyCommand
      },
      {
        no: 3,
        name: "create_and_exercise",
        kind: "message",
        oneof: "command",
        T: () => CreateAndExerciseCommand
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.command = { 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.CreateCommand create */
        1:
          message.command = {
            oneofKind: "create",
            create: CreateCommand.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.command.create
            )
          };
          break;
        case /* com.daml.ledger.api.v2.ExerciseCommand exercise */
        2:
          message.command = {
            oneofKind: "exercise",
            exercise: ExerciseCommand.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.command.exercise
            )
          };
          break;
        case /* com.daml.ledger.api.v2.ExerciseByKeyCommand exercise_by_key */
        4:
          message.command = {
            oneofKind: "exerciseByKey",
            exerciseByKey: ExerciseByKeyCommand.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.command.exerciseByKey
            )
          };
          break;
        case /* com.daml.ledger.api.v2.CreateAndExerciseCommand create_and_exercise */
        3:
          message.command = {
            oneofKind: "createAndExercise",
            createAndExercise: CreateAndExerciseCommand.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.command.createAndExercise
            )
          };
          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.command.oneofKind === "create")
      CreateCommand.internalBinaryWrite(
        message.command.create,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.command.oneofKind === "exercise")
      ExerciseCommand.internalBinaryWrite(
        message.command.exercise,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.command.oneofKind === "createAndExercise")
      CreateAndExerciseCommand.internalBinaryWrite(
        message.command.createAndExercise,
        writer.tag(3, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.command.oneofKind === "exerciseByKey")
      ExerciseByKeyCommand.internalBinaryWrite(
        message.command.exerciseByKey,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const Command = new Command$Type();
class CreateCommand$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.CreateCommand", [
      {
        no: 1,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 2,
        name: "create_arguments",
        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 template_id */
        1:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* com.daml.ledger.api.v2.Record create_arguments */
        2:
          message.createArguments = Record.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.createArguments
          );
          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.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.createArguments)
      Record.internalBinaryWrite(
        message.createArguments,
        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 CreateCommand = new CreateCommand$Type();
class ExerciseCommand$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ExerciseCommand", [
      {
        no: 1,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 2,
        name: "contract_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "choice",
        kind: "scalar",
        T: 9
      },
      { no: 4, name: "choice_argument", kind: "message", T: () => Value }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.contractId = "";
    message.choice = "";
    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 template_id */
        1:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* string contract_id */
        2:
          message.contractId = reader.string();
          break;
        case /* string choice */
        3:
          message.choice = reader.string();
          break;
        case /* com.daml.ledger.api.v2.Value choice_argument */
        4:
          message.choiceArgument = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.choiceArgument
          );
          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.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.contractId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.contractId);
    if (message.choice !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.choice);
    if (message.choiceArgument)
      Value.internalBinaryWrite(
        message.choiceArgument,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const ExerciseCommand = new ExerciseCommand$Type();
class ExerciseByKeyCommand$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.ExerciseByKeyCommand", [
      {
        no: 1,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      { no: 2, name: "contract_key", kind: "message", T: () => Value },
      {
        no: 3,
        name: "choice",
        kind: "scalar",
        T: 9
      },
      { no: 4, name: "choice_argument", kind: "message", T: () => Value }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.choice = "";
    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 template_id */
        1:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* com.daml.ledger.api.v2.Value contract_key */
        2:
          message.contractKey = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.contractKey
          );
          break;
        case /* string choice */
        3:
          message.choice = reader.string();
          break;
        case /* com.daml.ledger.api.v2.Value choice_argument */
        4:
          message.choiceArgument = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.choiceArgument
          );
          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.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.contractKey)
      Value.internalBinaryWrite(
        message.contractKey,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.choice !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.choice);
    if (message.choiceArgument)
      Value.internalBinaryWrite(
        message.choiceArgument,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const ExerciseByKeyCommand = new ExerciseByKeyCommand$Type();
class CreateAndExerciseCommand$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.CreateAndExerciseCommand", [
      {
        no: 1,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 2,
        name: "create_arguments",
        kind: "message",
        T: () => Record
      },
      {
        no: 3,
        name: "choice",
        kind: "scalar",
        T: 9
      },
      { no: 4, name: "choice_argument", kind: "message", T: () => Value }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.choice = "";
    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 template_id */
        1:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* com.daml.ledger.api.v2.Record create_arguments */
        2:
          message.createArguments = Record.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.createArguments
          );
          break;
        case /* string choice */
        3:
          message.choice = reader.string();
          break;
        case /* com.daml.ledger.api.v2.Value choice_argument */
        4:
          message.choiceArgument = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.choiceArgument
          );
          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.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.createArguments)
      Record.internalBinaryWrite(
        message.createArguments,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.choice !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.choice);
    if (message.choiceArgument)
      Value.internalBinaryWrite(
        message.choiceArgument,
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const CreateAndExerciseCommand = new CreateAndExerciseCommand$Type();
class DisclosedContract$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.DisclosedContract", [
      {
        no: 1,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 2,
        name: "contract_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "created_event_blob",
        kind: "scalar",
        T: 12
      },
      {
        no: 4,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.contractId = "";
    message.createdEventBlob = new Uint8Array(0);
    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.Identifier template_id */
        1:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* string contract_id */
        2:
          message.contractId = reader.string();
          break;
        case /* bytes created_event_blob */
        3:
          message.createdEventBlob = reader.bytes();
          break;
        case /* string synchronizer_id */
        4:
          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.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.contractId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.contractId);
    if (message.createdEventBlob.length)
      writer.tag(3, WireType.LengthDelimited).bytes(message.createdEventBlob);
    if (message.synchronizerId !== "")
      writer.tag(4, WireType.LengthDelimited).string(message.synchronizerId);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const DisclosedContract = new DisclosedContract$Type();
class Commands$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.Commands", [
      {
        no: 1,
        name: "workflow_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "user_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 3,
        name: "command_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 4,
        name: "commands",
        kind: "message",
        repeat: 2,
        T: () => Command
      },
      {
        no: 5,
        name: "deduplication_duration",
        kind: "message",
        oneof: "deduplicationPeriod",
        T: () => Duration
      },
      {
        no: 6,
        name: "deduplication_offset",
        kind: "scalar",
        oneof: "deduplicationPeriod",
        T: 3,
        L: 0
      },
      {
        no: 7,
        name: "min_ledger_time_abs",
        kind: "message",
        T: () => Timestamp
      },
      {
        no: 8,
        name: "min_ledger_time_rel",
        kind: "message",
        T: () => Duration
      },
      {
        no: 9,
        name: "act_as",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 10,
        name: "read_as",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 11,
        name: "submission_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 12,
        name: "disclosed_contracts",
        kind: "message",
        repeat: 2,
        T: () => DisclosedContract
      },
      {
        no: 13,
        name: "synchronizer_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 14,
        name: "package_id_selection_preference",
        kind: "scalar",
        repeat: 2,
        T: 9
      },
      {
        no: 15,
        name: "prefetch_contract_keys",
        kind: "message",
        repeat: 2,
        T: () => PrefetchContractKey
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.workflowId = "";
    message.userId = "";
    message.commandId = "";
    message.commands = [];
    message.deduplicationPeriod = { oneofKind: void 0 };
    message.actAs = [];
    message.readAs = [];
    message.submissionId = "";
    message.disclosedContracts = [];
    message.synchronizerId = "";
    message.packageIdSelectionPreference = [];
    message.prefetchContractKeys = [];
    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 workflow_id */
        1:
          message.workflowId = reader.string();
          break;
        case /* string user_id */
        2:
          message.userId = reader.string();
          break;
        case /* string command_id */
        3:
          message.commandId = reader.string();
          break;
        case /* repeated com.daml.ledger.api.v2.Command commands */
        4:
          message.commands.push(
            Command.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* google.protobuf.Duration deduplication_duration */
        5:
          message.deduplicationPeriod = {
            oneofKind: "deduplicationDuration",
            deduplicationDuration: Duration.internalBinaryRead(
              reader,
              reader.uint32(),
              options,
              message.deduplicationPeriod.deduplicationDuration
            )
          };
          break;
        case /* int64 deduplication_offset */
        6:
          message.deduplicationPeriod = {
            oneofKind: "deduplicationOffset",
            deduplicationOffset: reader.int64().toBigInt()
          };
          break;
        case /* google.protobuf.Timestamp min_ledger_time_abs */
        7:
          message.minLedgerTimeAbs = Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.minLedgerTimeAbs
          );
          break;
        case /* google.protobuf.Duration min_ledger_time_rel */
        8:
          message.minLedgerTimeRel = Duration.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.minLedgerTimeRel
          );
          break;
        case /* repeated string act_as */
        9:
          message.actAs.push(reader.string());
          break;
        case /* repeated string read_as */
        10:
          message.readAs.push(reader.string());
          break;
        case /* string submission_id */
        11:
          message.submissionId = reader.string();
          break;
        case /* repeated com.daml.ledger.api.v2.DisclosedContract disclosed_contracts */
        12:
          message.disclosedContracts.push(
            DisclosedContract.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* string synchronizer_id */
        13:
          message.synchronizerId = reader.string();
          break;
        case /* repeated string package_id_selection_preference */
        14:
          message.packageIdSelectionPreference.push(reader.string());
          break;
        case /* repeated com.daml.ledger.api.v2.PrefetchContractKey prefetch_contract_keys */
        15:
          message.prefetchContractKeys.push(
            PrefetchContractKey.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.workflowId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.workflowId);
    if (message.userId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.userId);
    if (message.commandId !== "")
      writer.tag(3, WireType.LengthDelimited).string(message.commandId);
    for (let i = 0; i < message.commands.length; i++)
      Command.internalBinaryWrite(
        message.commands[i],
        writer.tag(4, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.deduplicationPeriod.oneofKind === "deduplicationDuration")
      Duration.internalBinaryWrite(
        message.deduplicationPeriod.deduplicationDuration,
        writer.tag(5, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.deduplicationPeriod.oneofKind === "deduplicationOffset")
      writer.tag(6, WireType.Varint).int64(message.deduplicationPeriod.deduplicationOffset);
    if (message.minLedgerTimeAbs)
      Timestamp.internalBinaryWrite(
        message.minLedgerTimeAbs,
        writer.tag(7, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.minLedgerTimeRel)
      Duration.internalBinaryWrite(
        message.minLedgerTimeRel,
        writer.tag(8, WireType.LengthDelimited).fork(),
        options
      ).join();
    for (let i = 0; i < message.actAs.length; i++)
      writer.tag(9, WireType.LengthDelimited).string(message.actAs[i]);
    for (let i = 0; i < message.readAs.length; i++)
      writer.tag(10, WireType.LengthDelimited).string(message.readAs[i]);
    if (message.submissionId !== "")
      writer.tag(11, WireType.LengthDelimited).string(message.submissionId);
    for (let i = 0; i < message.disclosedContracts.length; i++)
      DisclosedContract.internalBinaryWrite(
        message.disclosedContracts[i],
        writer.tag(12, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.synchronizerId !== "")
      writer.tag(13, WireType.LengthDelimited).string(message.synchronizerId);
    for (let i = 0; i < message.packageIdSelectionPreference.length; i++)
      writer.tag(14, WireType.LengthDelimited).string(message.packageIdSelectionPreference[i]);
    for (let i = 0; i < message.prefetchContractKeys.length; i++)
      PrefetchContractKey.internalBinaryWrite(
        message.prefetchContractKeys[i],
        writer.tag(15, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const Commands = new Commands$Type();
class PrefetchContractKey$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.PrefetchContractKey", [
      {
        no: 1,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      { no: 2, name: "contract_key", kind: "message", T: () => Value }
    ]);
  }
  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 template_id */
        1:
          message.templateId = Identifier.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.templateId
          );
          break;
        case /* com.daml.ledger.api.v2.Value contract_key */
        2:
          message.contractKey = Value.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.contractKey
          );
          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.templateId)
      Identifier.internalBinaryWrite(
        message.templateId,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.contractKey)
      Value.internalBinaryWrite(
        message.contractKey,
        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 PrefetchContractKey = new PrefetchContractKey$Type();
export {
  Command,
  Commands,
  CreateAndExerciseCommand,
  CreateCommand,
  DisclosedContract,
  ExerciseByKeyCommand,
  ExerciseCommand,
  PrefetchContractKey
};
//# sourceMappingURL=commands.js.map