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 { Reassignment } from "./reassignment.js";
import { EventFormat } from "./transaction_filter.js";
import { ReassignmentCommands } from "./reassignment_commands.js";
import { TransactionTree } from "./transaction.js";
import { Transaction } from "./transaction.js";
import { TransactionFormat } from "./transaction_filter.js";
import { Commands } from "./commands.js";
class SubmitAndWaitRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.SubmitAndWaitRequest", [
      { no: 1, name: "commands", kind: "message", T: () => Commands }
    ]);
  }
  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.Commands commands */
        1:
          message.commands = Commands.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.commands
          );
          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.commands)
      Commands.internalBinaryWrite(
        message.commands,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const SubmitAndWaitRequest = new SubmitAndWaitRequest$Type();
class SubmitAndWaitForTransactionRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.SubmitAndWaitForTransactionRequest", [
      { no: 1, name: "commands", kind: "message", T: () => Commands },
      {
        no: 2,
        name: "transaction_format",
        kind: "message",
        T: () => TransactionFormat
      }
    ]);
  }
  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.Commands commands */
        1:
          message.commands = Commands.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.commands
          );
          break;
        case /* com.daml.ledger.api.v2.TransactionFormat transaction_format */
        2:
          message.transactionFormat = TransactionFormat.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.transactionFormat
          );
          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.commands)
      Commands.internalBinaryWrite(
        message.commands,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.transactionFormat)
      TransactionFormat.internalBinaryWrite(
        message.transactionFormat,
        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 SubmitAndWaitForTransactionRequest = new SubmitAndWaitForTransactionRequest$Type();
class SubmitAndWaitResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.SubmitAndWaitResponse", [
      {
        no: 1,
        name: "update_id",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "completion_offset",
        kind: "scalar",
        T: 3,
        L: 0
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.updateId = "";
    message.completionOffset = 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 update_id */
        1:
          message.updateId = reader.string();
          break;
        case /* int64 completion_offset */
        2:
          message.completionOffset = 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.updateId !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.updateId);
    if (message.completionOffset !== 0n)
      writer.tag(2, WireType.Varint).int64(message.completionOffset);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const SubmitAndWaitResponse = new SubmitAndWaitResponse$Type();
class SubmitAndWaitForTransactionResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.SubmitAndWaitForTransactionResponse", [
      {
        no: 1,
        name: "transaction",
        kind: "message",
        T: () => Transaction
      }
    ]);
  }
  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.Transaction transaction */
        1:
          message.transaction = Transaction.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.transaction
          );
          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.transaction)
      Transaction.internalBinaryWrite(
        message.transaction,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const SubmitAndWaitForTransactionResponse = new SubmitAndWaitForTransactionResponse$Type();
class SubmitAndWaitForTransactionTreeResponse$Type extends MessageType {
  constructor() {
    super(
      "com.daml.ledger.api.v2.SubmitAndWaitForTransactionTreeResponse",
      [
        {
          no: 1,
          name: "transaction",
          kind: "message",
          T: () => TransactionTree
        }
      ]
    );
  }
  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.TransactionTree transaction */
        1:
          message.transaction = TransactionTree.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.transaction
          );
          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.transaction)
      TransactionTree.internalBinaryWrite(
        message.transaction,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const SubmitAndWaitForTransactionTreeResponse = new SubmitAndWaitForTransactionTreeResponse$Type();
class SubmitAndWaitForReassignmentRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.SubmitAndWaitForReassignmentRequest", [
      {
        no: 1,
        name: "reassignment_commands",
        kind: "message",
        T: () => ReassignmentCommands
      },
      {
        no: 2,
        name: "event_format",
        kind: "message",
        T: () => EventFormat
      }
    ]);
  }
  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.ReassignmentCommands reassignment_commands */
        1:
          message.reassignmentCommands = ReassignmentCommands.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.reassignmentCommands
          );
          break;
        case /* com.daml.ledger.api.v2.EventFormat event_format */
        2:
          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.reassignmentCommands)
      ReassignmentCommands.internalBinaryWrite(
        message.reassignmentCommands,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.eventFormat)
      EventFormat.internalBinaryWrite(
        message.eventFormat,
        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 SubmitAndWaitForReassignmentRequest = new SubmitAndWaitForReassignmentRequest$Type();
class SubmitAndWaitForReassignmentResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.SubmitAndWaitForReassignmentResponse", [
      {
        no: 1,
        name: "reassignment",
        kind: "message",
        T: () => Reassignment
      }
    ]);
  }
  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.Reassignment reassignment */
        1:
          message.reassignment = Reassignment.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.reassignment
          );
          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.reassignment)
      Reassignment.internalBinaryWrite(
        message.reassignment,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const SubmitAndWaitForReassignmentResponse = new SubmitAndWaitForReassignmentResponse$Type();
const CommandService = new ServiceType(
  "com.daml.ledger.api.v2.CommandService",
  [
    {
      name: "SubmitAndWait",
      options: {},
      I: SubmitAndWaitRequest,
      O: SubmitAndWaitResponse
    },
    {
      name: "SubmitAndWaitForTransaction",
      options: {},
      I: SubmitAndWaitForTransactionRequest,
      O: SubmitAndWaitForTransactionResponse
    },
    {
      name: "SubmitAndWaitForTransactionTree",
      options: {},
      I: SubmitAndWaitRequest,
      O: SubmitAndWaitForTransactionTreeResponse
    },
    {
      name: "SubmitAndWaitForReassignment",
      options: {},
      I: SubmitAndWaitForReassignmentRequest,
      O: SubmitAndWaitForReassignmentResponse
    }
  ]
);
export {
  CommandService,
  SubmitAndWaitForReassignmentRequest,
  SubmitAndWaitForReassignmentResponse,
  SubmitAndWaitForTransactionRequest,
  SubmitAndWaitForTransactionResponse,
  SubmitAndWaitForTransactionTreeResponse,
  SubmitAndWaitRequest,
  SubmitAndWaitResponse
};
//# sourceMappingURL=command_service.js.map