var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var metrics_service_exports = {};
__export(metrics_service_exports, {
  ExportMetricsPartialSuccess: () => ExportMetricsPartialSuccess,
  ExportMetricsServiceRequest: () => ExportMetricsServiceRequest,
  ExportMetricsServiceResponse: () => ExportMetricsServiceResponse,
  MetricsServiceClientImpl: () => MetricsServiceClientImpl,
  MetricsServiceServiceName: () => MetricsServiceServiceName,
  protobufPackage: () => protobufPackage
});
module.exports = __toCommonJS(metrics_service_exports);
var import_global_this = __toESM(require("@babel/runtime-corejs3/core-js/global-this"));
var import_map = __toESM(require("@babel/runtime-corejs3/core-js/instance/map"));
var import_bind = __toESM(require("@babel/runtime-corejs3/core-js/instance/bind"));
var import_long = __toESM(require("long"));
var import_minimal = __toESM(require("protobufjs/minimal.js"));
var import_metrics = require("../../../metrics/v1/metrics.js");
const protobufPackage = "opentelemetry.proto.collector.metrics.v1";
function createBaseExportMetricsServiceRequest() {
  return {
    resourceMetrics: []
  };
}
const ExportMetricsServiceRequest = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    for (const v of message.resourceMetrics) {
      import_metrics.ResourceMetrics.encode(v, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseExportMetricsServiceRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }
          message.resourceMetrics.push(import_metrics.ResourceMetrics.decode(reader, reader.uint32()));
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    var _context;
    return {
      resourceMetrics: import_global_this.default.Array.isArray(object?.resourceMetrics) ? (0, import_map.default)(_context = object.resourceMetrics).call(_context, (e) => import_metrics.ResourceMetrics.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.resourceMetrics?.length) {
      var _context2;
      obj.resourceMetrics = (0, import_map.default)(_context2 = message.resourceMetrics).call(_context2, (e) => import_metrics.ResourceMetrics.toJSON(e));
    }
    return obj;
  },
  create(base) {
    return ExportMetricsServiceRequest.fromPartial(base ?? {});
  },
  fromPartial(object) {
    var _context3, _context4;
    const message = createBaseExportMetricsServiceRequest();
    message.resourceMetrics = ((_context3 = object.resourceMetrics) == null ? void 0 : (0, import_bind.default)(_context4 = Function.call).call(_context4, (0, import_map.default)(_context3), _context3))?.((e) => import_metrics.ResourceMetrics.fromPartial(e)) || [];
    return message;
  }
};
function createBaseExportMetricsServiceResponse() {
  return {
    partialSuccess: void 0
  };
}
const ExportMetricsServiceResponse = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.partialSuccess !== void 0) {
      ExportMetricsPartialSuccess.encode(message.partialSuccess, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseExportMetricsServiceResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }
          message.partialSuccess = ExportMetricsPartialSuccess.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    return {
      partialSuccess: isSet(object.partialSuccess) ? ExportMetricsPartialSuccess.fromJSON(object.partialSuccess) : void 0
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.partialSuccess !== void 0) {
      obj.partialSuccess = ExportMetricsPartialSuccess.toJSON(message.partialSuccess);
    }
    return obj;
  },
  create(base) {
    return ExportMetricsServiceResponse.fromPartial(base ?? {});
  },
  fromPartial(object) {
    const message = createBaseExportMetricsServiceResponse();
    message.partialSuccess = object.partialSuccess !== void 0 && object.partialSuccess !== null ? ExportMetricsPartialSuccess.fromPartial(object.partialSuccess) : void 0;
    return message;
  }
};
function createBaseExportMetricsPartialSuccess() {
  return {
    rejectedDataPoints: 0,
    errorMessage: ""
  };
}
const ExportMetricsPartialSuccess = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.rejectedDataPoints !== 0) {
      writer.uint32(8).int64(message.rejectedDataPoints);
    }
    if (message.errorMessage !== "") {
      writer.uint32(18).string(message.errorMessage);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseExportMetricsPartialSuccess();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }
          message.rejectedDataPoints = longToNumber(reader.int64());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }
          message.errorMessage = reader.string();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    return {
      rejectedDataPoints: isSet(object.rejectedDataPoints) ? import_global_this.default.Number(object.rejectedDataPoints) : 0,
      errorMessage: isSet(object.errorMessage) ? import_global_this.default.String(object.errorMessage) : ""
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.rejectedDataPoints !== 0) {
      obj.rejectedDataPoints = Math.round(message.rejectedDataPoints);
    }
    if (message.errorMessage !== "") {
      obj.errorMessage = message.errorMessage;
    }
    return obj;
  },
  create(base) {
    return ExportMetricsPartialSuccess.fromPartial(base ?? {});
  },
  fromPartial(object) {
    const message = createBaseExportMetricsPartialSuccess();
    message.rejectedDataPoints = object.rejectedDataPoints ?? 0;
    message.errorMessage = object.errorMessage ?? "";
    return message;
  }
};
const MetricsServiceServiceName = "opentelemetry.proto.collector.metrics.v1.MetricsService";
class MetricsServiceClientImpl {
  constructor(rpc, opts) {
    var _context5;
    this.rpc = void 0;
    this.service = void 0;
    this.service = opts?.service || MetricsServiceServiceName;
    this.rpc = rpc;
    this.Export = (0, import_bind.default)(_context5 = this.Export).call(_context5, this);
  }
  Export(request) {
    const data = ExportMetricsServiceRequest.encode(request).finish();
    const promise = this.rpc.request(this.service, "Export", data);
    return promise.then((data2) => ExportMetricsServiceResponse.decode(import_minimal.default.Reader.create(data2)));
  }
}
function longToNumber(long) {
  if (long.gt(import_global_this.default.Number.MAX_SAFE_INTEGER)) {
    throw new import_global_this.default.Error("Value is larger than Number.MAX_SAFE_INTEGER");
  }
  return long.toNumber();
}
if (import_minimal.default.util.Long !== import_long.default) {
  import_minimal.default.util.Long = import_long.default;
  import_minimal.default.configure();
}
function isSet(value) {
  return value !== null && value !== void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ExportMetricsPartialSuccess,
  ExportMetricsServiceRequest,
  ExportMetricsServiceResponse,
  MetricsServiceClientImpl,
  MetricsServiceServiceName,
  protobufPackage
});
//# sourceMappingURL=metrics_service.js.map
