"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportServiceClient = exports.ReportServiceService = exports.CalculateReportKpiValuesResponse = exports.CalculateReportKpiValuesRequest = exports.GetTableReportResponse_CasesEntry = exports.GetTableReportResponse = exports.GetTableReportRequest = 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 status_1 = require("../../../../../yandex/cloud/loadtesting/api/v1/report/status");
const report_1 = require("../../../../../yandex/cloud/loadtesting/api/v1/report/table/report");
const kpi_1 = require("../../../../../yandex/cloud/loadtesting/api/v1/report/kpi");
const kpi_value_1 = require("../../../../../yandex/cloud/loadtesting/api/v1/report/kpi_value");
exports.protobufPackage = 'yandex.cloud.loadtesting.api.v1';
const baseGetTableReportRequest = { testId: '' };
exports.GetTableReportRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.testId !== '') {
            writer.uint32(10).string(message.testId);
        }
        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({}, baseGetTableReportRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.testId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetTableReportRequest);
        message.testId =
            object.testId !== undefined && object.testId !== null ? String(object.testId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.testId !== undefined && (obj.testId = message.testId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGetTableReportRequest);
        message.testId = (_a = object.testId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseGetTableReportResponse = { status: 0 };
exports.GetTableReportResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.status !== 0) {
            writer.uint32(8).int32(message.status);
        }
        if (message.overall !== undefined) {
            report_1.Report.encode(message.overall, writer.uint32(18).fork()).ldelim();
        }
        Object.entries(message.cases).forEach(([key, value]) => {
            exports.GetTableReportResponse_CasesEntry.encode({ key: key, value }, 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({}, baseGetTableReportResponse);
        message.cases = {};
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.status = reader.int32();
                    break;
                case 2:
                    message.overall = report_1.Report.decode(reader, reader.uint32());
                    break;
                case 3:
                    const entry3 = exports.GetTableReportResponse_CasesEntry.decode(reader, reader.uint32());
                    if (entry3.value !== undefined) {
                        message.cases[entry3.key] = entry3.value;
                    }
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseGetTableReportResponse);
        message.status =
            object.status !== undefined && object.status !== null
                ? (0, status_1.statusFromJSON)(object.status)
                : 0;
        message.overall =
            object.overall !== undefined && object.overall !== null
                ? report_1.Report.fromJSON(object.overall)
                : undefined;
        message.cases = Object.entries((_a = object.cases) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = report_1.Report.fromJSON(value);
            return acc;
        }, {});
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.status !== undefined && (obj.status = (0, status_1.statusToJSON)(message.status));
        message.overall !== undefined &&
            (obj.overall = message.overall ? report_1.Report.toJSON(message.overall) : undefined);
        obj.cases = {};
        if (message.cases) {
            Object.entries(message.cases).forEach(([k, v]) => {
                obj.cases[k] = report_1.Report.toJSON(v);
            });
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseGetTableReportResponse);
        message.status = (_a = object.status) !== null && _a !== void 0 ? _a : 0;
        message.overall =
            object.overall !== undefined && object.overall !== null
                ? report_1.Report.fromPartial(object.overall)
                : undefined;
        message.cases = Object.entries((_b = object.cases) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = report_1.Report.fromPartial(value);
            }
            return acc;
        }, {});
        return message;
    },
};
const baseGetTableReportResponse_CasesEntry = { key: '' };
exports.GetTableReportResponse_CasesEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.key !== '') {
            writer.uint32(10).string(message.key);
        }
        if (message.value !== undefined) {
            report_1.Report.encode(message.value, 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({}, baseGetTableReportResponse_CasesEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.key = reader.string();
                    break;
                case 2:
                    message.value = report_1.Report.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetTableReportResponse_CasesEntry);
        message.key = object.key !== undefined && object.key !== null ? String(object.key) : '';
        message.value =
            object.value !== undefined && object.value !== null
                ? report_1.Report.fromJSON(object.value)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.key !== undefined && (obj.key = message.key);
        message.value !== undefined &&
            (obj.value = message.value ? report_1.Report.toJSON(message.value) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGetTableReportResponse_CasesEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value =
            object.value !== undefined && object.value !== null
                ? report_1.Report.fromPartial(object.value)
                : undefined;
        return message;
    },
};
const baseCalculateReportKpiValuesRequest = { folderId: '', testFilter: '', testCase: '' };
exports.CalculateReportKpiValuesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.folderId !== '') {
            writer.uint32(10).string(message.folderId);
        }
        if (message.testFilter !== '') {
            writer.uint32(18).string(message.testFilter);
        }
        if (message.testCase !== '') {
            writer.uint32(26).string(message.testCase);
        }
        if (message.kpi !== undefined) {
            kpi_1.Kpi.encode(message.kpi, writer.uint32(34).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({}, baseCalculateReportKpiValuesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.folderId = reader.string();
                    break;
                case 2:
                    message.testFilter = reader.string();
                    break;
                case 3:
                    message.testCase = reader.string();
                    break;
                case 4:
                    message.kpi = kpi_1.Kpi.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCalculateReportKpiValuesRequest);
        message.folderId =
            object.folderId !== undefined && object.folderId !== null
                ? String(object.folderId)
                : '';
        message.testFilter =
            object.testFilter !== undefined && object.testFilter !== null
                ? String(object.testFilter)
                : '';
        message.testCase =
            object.testCase !== undefined && object.testCase !== null
                ? String(object.testCase)
                : '';
        message.kpi =
            object.kpi !== undefined && object.kpi !== null ? kpi_1.Kpi.fromJSON(object.kpi) : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.folderId !== undefined && (obj.folderId = message.folderId);
        message.testFilter !== undefined && (obj.testFilter = message.testFilter);
        message.testCase !== undefined && (obj.testCase = message.testCase);
        message.kpi !== undefined && (obj.kpi = message.kpi ? kpi_1.Kpi.toJSON(message.kpi) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseCalculateReportKpiValuesRequest);
        message.folderId = (_a = object.folderId) !== null && _a !== void 0 ? _a : '';
        message.testFilter = (_b = object.testFilter) !== null && _b !== void 0 ? _b : '';
        message.testCase = (_c = object.testCase) !== null && _c !== void 0 ? _c : '';
        message.kpi =
            object.kpi !== undefined && object.kpi !== null
                ? kpi_1.Kpi.fromPartial(object.kpi)
                : undefined;
        return message;
    },
};
const baseCalculateReportKpiValuesResponse = { folderId: '' };
exports.CalculateReportKpiValuesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.folderId !== '') {
            writer.uint32(10).string(message.folderId);
        }
        for (const v of message.values) {
            kpi_value_1.KpiValue.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({}, baseCalculateReportKpiValuesResponse);
        message.values = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.folderId = reader.string();
                    break;
                case 2:
                    message.values.push(kpi_value_1.KpiValue.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseCalculateReportKpiValuesResponse);
        message.folderId =
            object.folderId !== undefined && object.folderId !== null
                ? String(object.folderId)
                : '';
        message.values = ((_a = object.values) !== null && _a !== void 0 ? _a : []).map((e) => kpi_value_1.KpiValue.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.folderId !== undefined && (obj.folderId = message.folderId);
        if (message.values) {
            obj.values = message.values.map((e) => (e ? kpi_value_1.KpiValue.toJSON(e) : undefined));
        }
        else {
            obj.values = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseCalculateReportKpiValuesResponse);
        message.folderId = (_a = object.folderId) !== null && _a !== void 0 ? _a : '';
        message.values = ((_b = object.values) === null || _b === void 0 ? void 0 : _b.map((e) => kpi_value_1.KpiValue.fromPartial(e))) || [];
        return message;
    },
};
/** A set of methods for managing test reports. */
exports.ReportServiceService = {
    /** Returns a report table for the specified test. */
    getTable: {
        path: '/yandex.cloud.loadtesting.api.v1.ReportService/GetTable',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GetTableReportRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GetTableReportRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.GetTableReportResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.GetTableReportResponse.decode(value),
    },
    /** Returns a list of KPI values for tests matching the specified filter. */
    calculateKpiValues: {
        path: '/yandex.cloud.loadtesting.api.v1.ReportService/CalculateKpiValues',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.CalculateReportKpiValuesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.CalculateReportKpiValuesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.CalculateReportKpiValuesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.CalculateReportKpiValuesResponse.decode(value),
    },
};
exports.ReportServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.ReportServiceService, 'yandex.cloud.loadtesting.api.v1.ReportService');
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
