"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProductUsageServiceClient = exports.ProductUsageServiceService = exports.WriteUsageResponse = exports.WriteUsageRequest = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const grpc_js_1 = require("@grpc/grpc-js");
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const usage_record_1 = require("../../../../../yandex/cloud/marketplace/metering/v1/usage_record");
exports.protobufPackage = 'yandex.cloud.marketplace.metering.v1';
const baseWriteUsageRequest = { dryRun: false, productInstanceId: '' };
exports.WriteUsageRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.dryRun === true) {
            writer.uint32(8).bool(message.dryRun);
        }
        if (message.productInstanceId !== '') {
            writer.uint32(18).string(message.productInstanceId);
        }
        for (const v of message.usageRecords) {
            usage_record_1.UsageRecord.encode(v, writer.uint32(26).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseWriteUsageRequest);
        message.usageRecords = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.dryRun = reader.bool();
                    break;
                case 2:
                    message.productInstanceId = reader.string();
                    break;
                case 3:
                    message.usageRecords.push(usage_record_1.UsageRecord.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseWriteUsageRequest);
        message.dryRun =
            object.dryRun !== undefined && object.dryRun !== null ? Boolean(object.dryRun) : false;
        message.productInstanceId =
            object.productInstanceId !== undefined && object.productInstanceId !== null
                ? String(object.productInstanceId)
                : '';
        message.usageRecords = ((_a = object.usageRecords) !== null && _a !== void 0 ? _a : []).map((e) => usage_record_1.UsageRecord.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.dryRun !== undefined && (obj.dryRun = message.dryRun);
        message.productInstanceId !== undefined &&
            (obj.productInstanceId = message.productInstanceId);
        if (message.usageRecords) {
            obj.usageRecords = message.usageRecords.map((e) => e ? usage_record_1.UsageRecord.toJSON(e) : undefined);
        }
        else {
            obj.usageRecords = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseWriteUsageRequest);
        message.dryRun = (_a = object.dryRun) !== null && _a !== void 0 ? _a : false;
        message.productInstanceId = (_b = object.productInstanceId) !== null && _b !== void 0 ? _b : '';
        message.usageRecords = ((_c = object.usageRecords) === null || _c === void 0 ? void 0 : _c.map((e) => usage_record_1.UsageRecord.fromPartial(e))) || [];
        return message;
    },
};
const baseWriteUsageResponse = {};
exports.WriteUsageResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.accepted) {
            usage_record_1.AcceptedUsageRecord.encode(v, writer.uint32(10).fork()).ldelim();
        }
        for (const v of message.rejected) {
            usage_record_1.RejectedUsageRecord.encode(v, writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseWriteUsageResponse);
        message.accepted = [];
        message.rejected = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.accepted.push(usage_record_1.AcceptedUsageRecord.decode(reader, reader.uint32()));
                    break;
                case 2:
                    message.rejected.push(usage_record_1.RejectedUsageRecord.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseWriteUsageResponse);
        message.accepted = ((_a = object.accepted) !== null && _a !== void 0 ? _a : []).map((e) => usage_record_1.AcceptedUsageRecord.fromJSON(e));
        message.rejected = ((_b = object.rejected) !== null && _b !== void 0 ? _b : []).map((e) => usage_record_1.RejectedUsageRecord.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.accepted) {
            obj.accepted = message.accepted.map((e) => e ? usage_record_1.AcceptedUsageRecord.toJSON(e) : undefined);
        }
        else {
            obj.accepted = [];
        }
        if (message.rejected) {
            obj.rejected = message.rejected.map((e) => e ? usage_record_1.RejectedUsageRecord.toJSON(e) : undefined);
        }
        else {
            obj.rejected = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseWriteUsageResponse);
        message.accepted = ((_a = object.accepted) === null || _a === void 0 ? void 0 : _a.map((e) => usage_record_1.AcceptedUsageRecord.fromPartial(e))) || [];
        message.rejected = ((_b = object.rejected) === null || _b === void 0 ? void 0 : _b.map((e) => usage_record_1.RejectedUsageRecord.fromPartial(e))) || [];
        return message;
    },
};
exports.ProductUsageServiceService = {
    /** Writes product's usage (authenticated by publisher's service account) */
    write: {
        path: '/yandex.cloud.marketplace.metering.v1.ProductUsageService/Write',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.WriteUsageRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.WriteUsageRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.WriteUsageResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.WriteUsageResponse.decode(value),
    },
};
exports.ProductUsageServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.ProductUsageServiceService, 'yandex.cloud.marketplace.metering.v1.ProductUsageService');
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
