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 { Value } from "../value.js";
import { Identifier } from "../value.js";
import { Command } from "../commands.js";
import { Completion } from "../completion.js";
import { Timestamp } from "../../../../../../google/protobuf/timestamp.js";
var CommandState = /* @__PURE__ */ ((CommandState2) => {
  CommandState2[CommandState2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
  CommandState2[CommandState2["PENDING"] = 1] = "PENDING";
  CommandState2[CommandState2["SUCCEEDED"] = 2] = "SUCCEEDED";
  CommandState2[CommandState2["FAILED"] = 3] = "FAILED";
  return CommandState2;
})(CommandState || {});
class GetCommandStatusRequest$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.admin.GetCommandStatusRequest", [
      {
        no: 1,
        name: "command_id_prefix",
        kind: "scalar",
        T: 9
      },
      {
        no: 2,
        name: "state",
        kind: "enum",
        T: () => [
          "com.daml.ledger.api.v2.admin.CommandState",
          CommandState,
          "COMMAND_STATE_"
        ]
      },
      {
        no: 3,
        name: "limit",
        kind: "scalar",
        T: 13
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.commandIdPrefix = "";
    message.state = 0;
    message.limit = 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 /* string command_id_prefix */
        1:
          message.commandIdPrefix = reader.string();
          break;
        case /* com.daml.ledger.api.v2.admin.CommandState state */
        2:
          message.state = reader.int32();
          break;
        case /* uint32 limit */
        3:
          message.limit = reader.uint32();
          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.commandIdPrefix !== "")
      writer.tag(1, WireType.LengthDelimited).string(message.commandIdPrefix);
    if (message.state !== 0)
      writer.tag(2, WireType.Varint).int32(message.state);
    if (message.limit !== 0)
      writer.tag(3, WireType.Varint).uint32(message.limit);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const GetCommandStatusRequest = new GetCommandStatusRequest$Type();
class GetCommandStatusResponse$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.admin.GetCommandStatusResponse", [
      {
        no: 1,
        name: "command_status",
        kind: "message",
        repeat: 2,
        T: () => CommandStatus
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.commandStatus = [];
    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 /* repeated com.daml.ledger.api.v2.admin.CommandStatus command_status */
        1:
          message.commandStatus.push(
            CommandStatus.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) {
    for (let i = 0; i < message.commandStatus.length; i++)
      CommandStatus.internalBinaryWrite(
        message.commandStatus[i],
        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 GetCommandStatusResponse = new GetCommandStatusResponse$Type();
class CommandStatus$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.admin.CommandStatus", [
      { no: 1, name: "started", kind: "message", T: () => Timestamp },
      { no: 2, name: "completed", kind: "message", T: () => Timestamp },
      { no: 3, name: "completion", kind: "message", T: () => Completion },
      {
        no: 4,
        name: "state",
        kind: "enum",
        T: () => [
          "com.daml.ledger.api.v2.admin.CommandState",
          CommandState,
          "COMMAND_STATE_"
        ]
      },
      {
        no: 5,
        name: "commands",
        kind: "message",
        repeat: 2,
        T: () => Command
      },
      {
        no: 6,
        name: "request_statistics",
        kind: "message",
        T: () => RequestStatistics
      },
      {
        no: 7,
        name: "updates",
        kind: "message",
        T: () => CommandUpdates
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.state = 0;
    message.commands = [];
    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 /* google.protobuf.Timestamp started */
        1:
          message.started = Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.started
          );
          break;
        case /* google.protobuf.Timestamp completed */
        2:
          message.completed = Timestamp.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.completed
          );
          break;
        case /* com.daml.ledger.api.v2.Completion completion */
        3:
          message.completion = Completion.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.completion
          );
          break;
        case /* com.daml.ledger.api.v2.admin.CommandState state */
        4:
          message.state = reader.int32();
          break;
        case /* repeated com.daml.ledger.api.v2.Command commands */
        5:
          message.commands.push(
            Command.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* com.daml.ledger.api.v2.admin.RequestStatistics request_statistics */
        6:
          message.requestStatistics = RequestStatistics.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.requestStatistics
          );
          break;
        case /* com.daml.ledger.api.v2.admin.CommandUpdates updates */
        7:
          message.updates = CommandUpdates.internalBinaryRead(
            reader,
            reader.uint32(),
            options,
            message.updates
          );
          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.started)
      Timestamp.internalBinaryWrite(
        message.started,
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.completed)
      Timestamp.internalBinaryWrite(
        message.completed,
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.completion)
      Completion.internalBinaryWrite(
        message.completion,
        writer.tag(3, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.state !== 0)
      writer.tag(4, WireType.Varint).int32(message.state);
    for (let i = 0; i < message.commands.length; i++)
      Command.internalBinaryWrite(
        message.commands[i],
        writer.tag(5, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.requestStatistics)
      RequestStatistics.internalBinaryWrite(
        message.requestStatistics,
        writer.tag(6, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.updates)
      CommandUpdates.internalBinaryWrite(
        message.updates,
        writer.tag(7, WireType.LengthDelimited).fork(),
        options
      ).join();
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const CommandStatus = new CommandStatus$Type();
class RequestStatistics$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.admin.RequestStatistics", [
      {
        no: 1,
        name: "envelopes",
        kind: "scalar",
        T: 13
      },
      {
        no: 2,
        name: "request_size",
        kind: "scalar",
        T: 13
      },
      {
        no: 3,
        name: "recipients",
        kind: "scalar",
        T: 13
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.envelopes = 0;
    message.requestSize = 0;
    message.recipients = 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 /* uint32 envelopes */
        1:
          message.envelopes = reader.uint32();
          break;
        case /* uint32 request_size */
        2:
          message.requestSize = reader.uint32();
          break;
        case /* uint32 recipients */
        3:
          message.recipients = reader.uint32();
          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.envelopes !== 0)
      writer.tag(1, WireType.Varint).uint32(message.envelopes);
    if (message.requestSize !== 0)
      writer.tag(2, WireType.Varint).uint32(message.requestSize);
    if (message.recipients !== 0)
      writer.tag(3, WireType.Varint).uint32(message.recipients);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const RequestStatistics = new RequestStatistics$Type();
class CommandUpdates$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.admin.CommandUpdates", [
      {
        no: 1,
        name: "created",
        kind: "message",
        repeat: 2,
        T: () => Contract
      },
      {
        no: 2,
        name: "archived",
        kind: "message",
        repeat: 2,
        T: () => Contract
      },
      {
        no: 3,
        name: "exercised",
        kind: "scalar",
        T: 13
      },
      {
        no: 4,
        name: "fetched",
        kind: "scalar",
        T: 13
      },
      {
        no: 5,
        name: "looked_up_by_key",
        kind: "scalar",
        T: 13
      }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.created = [];
    message.archived = [];
    message.exercised = 0;
    message.fetched = 0;
    message.lookedUpByKey = 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 /* repeated com.daml.ledger.api.v2.admin.Contract created */
        1:
          message.created.push(
            Contract.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* repeated com.daml.ledger.api.v2.admin.Contract archived */
        2:
          message.archived.push(
            Contract.internalBinaryRead(
              reader,
              reader.uint32(),
              options
            )
          );
          break;
        case /* uint32 exercised */
        3:
          message.exercised = reader.uint32();
          break;
        case /* uint32 fetched */
        4:
          message.fetched = reader.uint32();
          break;
        case /* uint32 looked_up_by_key */
        5:
          message.lookedUpByKey = reader.uint32();
          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) {
    for (let i = 0; i < message.created.length; i++)
      Contract.internalBinaryWrite(
        message.created[i],
        writer.tag(1, WireType.LengthDelimited).fork(),
        options
      ).join();
    for (let i = 0; i < message.archived.length; i++)
      Contract.internalBinaryWrite(
        message.archived[i],
        writer.tag(2, WireType.LengthDelimited).fork(),
        options
      ).join();
    if (message.exercised !== 0)
      writer.tag(3, WireType.Varint).uint32(message.exercised);
    if (message.fetched !== 0)
      writer.tag(4, WireType.Varint).uint32(message.fetched);
    if (message.lookedUpByKey !== 0)
      writer.tag(5, WireType.Varint).uint32(message.lookedUpByKey);
    let u = options.writeUnknownFields;
    if (u !== false)
      (u == true ? UnknownFieldHandler.onWrite : u)(
        this.typeName,
        message,
        writer
      );
    return writer;
  }
}
const CommandUpdates = new CommandUpdates$Type();
class Contract$Type extends MessageType {
  constructor() {
    super("com.daml.ledger.api.v2.admin.Contract", [
      {
        no: 1,
        name: "template_id",
        kind: "message",
        T: () => Identifier
      },
      {
        no: 2,
        name: "contract_id",
        kind: "scalar",
        T: 9
      },
      { no: 3, name: "contract_key", kind: "message", T: () => Value }
    ]);
  }
  create(value) {
    const message = globalThis.Object.create(this.messagePrototype);
    message.contractId = "";
    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 /* com.daml.ledger.api.v2.Value contract_key */
        3:
          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.contractId !== "")
      writer.tag(2, WireType.LengthDelimited).string(message.contractId);
    if (message.contractKey)
      Value.internalBinaryWrite(
        message.contractKey,
        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 Contract = new Contract$Type();
const CommandInspectionService = new ServiceType(
  "com.daml.ledger.api.v2.admin.CommandInspectionService",
  [
    {
      name: "GetCommandStatus",
      options: {},
      I: GetCommandStatusRequest,
      O: GetCommandStatusResponse
    }
  ]
);
export {
  CommandInspectionService,
  CommandState,
  CommandStatus,
  CommandUpdates,
  Contract,
  GetCommandStatusRequest,
  GetCommandStatusResponse,
  RequestStatistics
};
//# sourceMappingURL=command_inspection_service.js.map