"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImbalancePoint = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const timestamp_1 = require("../../../../../../google/protobuf/timestamp");
exports.protobufPackage = 'yandex.cloud.loadtesting.api.v1.test';
const baseImbalancePoint = { rps: 0, comment: '' };
exports.ImbalancePoint = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.at !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.at), writer.uint32(10).fork()).ldelim();
        }
        if (message.rps !== 0) {
            writer.uint32(16).int64(message.rps);
        }
        if (message.comment !== '') {
            writer.uint32(26).string(message.comment);
        }
        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({}, baseImbalancePoint);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.at = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 2:
                    message.rps = longToNumber(reader.int64());
                    break;
                case 3:
                    message.comment = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseImbalancePoint);
        message.at =
            object.at !== undefined && object.at !== null
                ? fromJsonTimestamp(object.at)
                : undefined;
        message.rps = object.rps !== undefined && object.rps !== null ? Number(object.rps) : 0;
        message.comment =
            object.comment !== undefined && object.comment !== null ? String(object.comment) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.at !== undefined && (obj.at = message.at.toISOString());
        message.rps !== undefined && (obj.rps = Math.round(message.rps));
        message.comment !== undefined && (obj.comment = message.comment);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseImbalancePoint);
        message.at = (_a = object.at) !== null && _a !== void 0 ? _a : undefined;
        message.rps = (_b = object.rps) !== null && _b !== void 0 ? _b : 0;
        message.comment = (_c = object.comment) !== null && _c !== void 0 ? _c : '';
        return message;
    },
};
var globalThis = (() => {
    if (typeof globalThis !== 'undefined')
        return globalThis;
    if (typeof self !== 'undefined')
        return self;
    if (typeof window !== 'undefined')
        return window;
    if (typeof global !== 'undefined')
        return global;
    throw 'Unable to locate global object';
})();
function toTimestamp(date) {
    const seconds = date.getTime() / 1000;
    const nanos = (date.getTime() % 1000) * 1000000;
    return { seconds, nanos };
}
function fromTimestamp(t) {
    let millis = t.seconds * 1000;
    millis += t.nanos / 1000000;
    return new Date(millis);
}
function fromJsonTimestamp(o) {
    if (o instanceof Date) {
        return o;
    }
    else if (typeof o === 'string') {
        return new Date(o);
    }
    else {
        return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
    }
}
function longToNumber(long) {
    if (long.gt(Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
    }
    return long.toNumber();
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
