"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReservedInstancePool_LabelsEntry = exports.ReservedInstancePool = exports.BootDiskSpec = exports.ProductIDs = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const instance_service_1 = require("../../../../yandex/cloud/compute/v1/instance_service");
const instance_1 = require("../../../../yandex/cloud/compute/v1/instance");
const timestamp_1 = require("../../../../google/protobuf/timestamp");
exports.protobufPackage = 'yandex.cloud.compute.v1';
const baseProductIDs = { productIds: '' };
exports.ProductIDs = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.productIds) {
            writer.uint32(10).string(v);
        }
        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({}, baseProductIDs);
        message.productIds = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.productIds.push(reader.string());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseProductIDs);
        message.productIds = ((_a = object.productIds) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.productIds) {
            obj.productIds = message.productIds.map((e) => e);
        }
        else {
            obj.productIds = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseProductIDs);
        message.productIds = ((_a = object.productIds) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
        return message;
    },
};
const baseBootDiskSpec = {};
exports.BootDiskSpec = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.diskId !== undefined) {
            writer.uint32(10).string(message.diskId);
        }
        if (message.imageId !== undefined) {
            writer.uint32(18).string(message.imageId);
        }
        if (message.snapshotId !== undefined) {
            writer.uint32(26).string(message.snapshotId);
        }
        if (message.productIds !== undefined) {
            exports.ProductIDs.encode(message.productIds, 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({}, baseBootDiskSpec);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.diskId = reader.string();
                    break;
                case 2:
                    message.imageId = reader.string();
                    break;
                case 3:
                    message.snapshotId = reader.string();
                    break;
                case 4:
                    message.productIds = exports.ProductIDs.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseBootDiskSpec);
        message.diskId =
            object.diskId !== undefined && object.diskId !== null
                ? String(object.diskId)
                : undefined;
        message.imageId =
            object.imageId !== undefined && object.imageId !== null
                ? String(object.imageId)
                : undefined;
        message.snapshotId =
            object.snapshotId !== undefined && object.snapshotId !== null
                ? String(object.snapshotId)
                : undefined;
        message.productIds =
            object.productIds !== undefined && object.productIds !== null
                ? exports.ProductIDs.fromJSON(object.productIds)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.diskId !== undefined && (obj.diskId = message.diskId);
        message.imageId !== undefined && (obj.imageId = message.imageId);
        message.snapshotId !== undefined && (obj.snapshotId = message.snapshotId);
        message.productIds !== undefined &&
            (obj.productIds = message.productIds
                ? exports.ProductIDs.toJSON(message.productIds)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseBootDiskSpec);
        message.diskId = (_a = object.diskId) !== null && _a !== void 0 ? _a : undefined;
        message.imageId = (_b = object.imageId) !== null && _b !== void 0 ? _b : undefined;
        message.snapshotId = (_c = object.snapshotId) !== null && _c !== void 0 ? _c : undefined;
        message.productIds =
            object.productIds !== undefined && object.productIds !== null
                ? exports.ProductIDs.fromPartial(object.productIds)
                : undefined;
        return message;
    },
};
const baseReservedInstancePool = {
    id: '',
    zoneId: '',
    cloudId: '',
    folderId: '',
    name: '',
    description: '',
    platformId: '',
    productIds: '',
    size: 0,
};
exports.ReservedInstancePool = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.zoneId !== '') {
            writer.uint32(18).string(message.zoneId);
        }
        if (message.cloudId !== '') {
            writer.uint32(26).string(message.cloudId);
        }
        if (message.folderId !== '') {
            writer.uint32(34).string(message.folderId);
        }
        if (message.name !== '') {
            writer.uint32(42).string(message.name);
        }
        if (message.description !== '') {
            writer.uint32(50).string(message.description);
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.ReservedInstancePool_LabelsEntry.encode({ key: key, value }, writer.uint32(58).fork()).ldelim();
        });
        if (message.createdAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(66).fork()).ldelim();
        }
        if (message.platformId !== '') {
            writer.uint32(74).string(message.platformId);
        }
        if (message.resourcesSpec !== undefined) {
            instance_service_1.ResourcesSpec.encode(message.resourcesSpec, writer.uint32(82).fork()).ldelim();
        }
        if (message.gpuSettings !== undefined) {
            instance_1.GpuSettings.encode(message.gpuSettings, writer.uint32(90).fork()).ldelim();
        }
        for (const v of message.productIds) {
            writer.uint32(98).string(v);
        }
        if (message.networkSettings !== undefined) {
            instance_1.NetworkSettings.encode(message.networkSettings, writer.uint32(106).fork()).ldelim();
        }
        if (message.size !== 0) {
            writer.uint32(112).int64(message.size);
        }
        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({}, baseReservedInstancePool);
        message.labels = {};
        message.productIds = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.zoneId = reader.string();
                    break;
                case 3:
                    message.cloudId = reader.string();
                    break;
                case 4:
                    message.folderId = reader.string();
                    break;
                case 5:
                    message.name = reader.string();
                    break;
                case 6:
                    message.description = reader.string();
                    break;
                case 7:
                    const entry7 = exports.ReservedInstancePool_LabelsEntry.decode(reader, reader.uint32());
                    if (entry7.value !== undefined) {
                        message.labels[entry7.key] = entry7.value;
                    }
                    break;
                case 8:
                    message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 9:
                    message.platformId = reader.string();
                    break;
                case 10:
                    message.resourcesSpec = instance_service_1.ResourcesSpec.decode(reader, reader.uint32());
                    break;
                case 11:
                    message.gpuSettings = instance_1.GpuSettings.decode(reader, reader.uint32());
                    break;
                case 12:
                    message.productIds.push(reader.string());
                    break;
                case 13:
                    message.networkSettings = instance_1.NetworkSettings.decode(reader, reader.uint32());
                    break;
                case 14:
                    message.size = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseReservedInstancePool);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.zoneId =
            object.zoneId !== undefined && object.zoneId !== null ? String(object.zoneId) : '';
        message.cloudId =
            object.cloudId !== undefined && object.cloudId !== null ? String(object.cloudId) : '';
        message.folderId =
            object.folderId !== undefined && object.folderId !== null
                ? String(object.folderId)
                : '';
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.labels = Object.entries((_a = object.labels) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.createdAt =
            object.createdAt !== undefined && object.createdAt !== null
                ? fromJsonTimestamp(object.createdAt)
                : undefined;
        message.platformId =
            object.platformId !== undefined && object.platformId !== null
                ? String(object.platformId)
                : '';
        message.resourcesSpec =
            object.resourcesSpec !== undefined && object.resourcesSpec !== null
                ? instance_service_1.ResourcesSpec.fromJSON(object.resourcesSpec)
                : undefined;
        message.gpuSettings =
            object.gpuSettings !== undefined && object.gpuSettings !== null
                ? instance_1.GpuSettings.fromJSON(object.gpuSettings)
                : undefined;
        message.productIds = ((_b = object.productIds) !== null && _b !== void 0 ? _b : []).map((e) => String(e));
        message.networkSettings =
            object.networkSettings !== undefined && object.networkSettings !== null
                ? instance_1.NetworkSettings.fromJSON(object.networkSettings)
                : undefined;
        message.size = object.size !== undefined && object.size !== null ? Number(object.size) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.zoneId !== undefined && (obj.zoneId = message.zoneId);
        message.cloudId !== undefined && (obj.cloudId = message.cloudId);
        message.folderId !== undefined && (obj.folderId = message.folderId);
        message.name !== undefined && (obj.name = message.name);
        message.description !== undefined && (obj.description = message.description);
        obj.labels = {};
        if (message.labels) {
            Object.entries(message.labels).forEach(([k, v]) => {
                obj.labels[k] = v;
            });
        }
        message.createdAt !== undefined && (obj.createdAt = message.createdAt.toISOString());
        message.platformId !== undefined && (obj.platformId = message.platformId);
        message.resourcesSpec !== undefined &&
            (obj.resourcesSpec = message.resourcesSpec
                ? instance_service_1.ResourcesSpec.toJSON(message.resourcesSpec)
                : undefined);
        message.gpuSettings !== undefined &&
            (obj.gpuSettings = message.gpuSettings
                ? instance_1.GpuSettings.toJSON(message.gpuSettings)
                : undefined);
        if (message.productIds) {
            obj.productIds = message.productIds.map((e) => e);
        }
        else {
            obj.productIds = [];
        }
        message.networkSettings !== undefined &&
            (obj.networkSettings = message.networkSettings
                ? instance_1.NetworkSettings.toJSON(message.networkSettings)
                : undefined);
        message.size !== undefined && (obj.size = Math.round(message.size));
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
        const message = Object.assign({}, baseReservedInstancePool);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.zoneId = (_b = object.zoneId) !== null && _b !== void 0 ? _b : '';
        message.cloudId = (_c = object.cloudId) !== null && _c !== void 0 ? _c : '';
        message.folderId = (_d = object.folderId) !== null && _d !== void 0 ? _d : '';
        message.name = (_e = object.name) !== null && _e !== void 0 ? _e : '';
        message.description = (_f = object.description) !== null && _f !== void 0 ? _f : '';
        message.labels = Object.entries((_g = object.labels) !== null && _g !== void 0 ? _g : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.createdAt = (_h = object.createdAt) !== null && _h !== void 0 ? _h : undefined;
        message.platformId = (_j = object.platformId) !== null && _j !== void 0 ? _j : '';
        message.resourcesSpec =
            object.resourcesSpec !== undefined && object.resourcesSpec !== null
                ? instance_service_1.ResourcesSpec.fromPartial(object.resourcesSpec)
                : undefined;
        message.gpuSettings =
            object.gpuSettings !== undefined && object.gpuSettings !== null
                ? instance_1.GpuSettings.fromPartial(object.gpuSettings)
                : undefined;
        message.productIds = ((_k = object.productIds) === null || _k === void 0 ? void 0 : _k.map((e) => e)) || [];
        message.networkSettings =
            object.networkSettings !== undefined && object.networkSettings !== null
                ? instance_1.NetworkSettings.fromPartial(object.networkSettings)
                : undefined;
        message.size = (_l = object.size) !== null && _l !== void 0 ? _l : 0;
        return message;
    },
};
const baseReservedInstancePool_LabelsEntry = { key: '', value: '' };
exports.ReservedInstancePool_LabelsEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.key !== '') {
            writer.uint32(10).string(message.key);
        }
        if (message.value !== '') {
            writer.uint32(18).string(message.value);
        }
        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({}, baseReservedInstancePool_LabelsEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.key = reader.string();
                    break;
                case 2:
                    message.value = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseReservedInstancePool_LabelsEntry);
        message.key = object.key !== undefined && object.key !== null ? String(object.key) : '';
        message.value =
            object.value !== undefined && object.value !== null ? String(object.value) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.key !== undefined && (obj.key = message.key);
        message.value !== undefined && (obj.value = message.value);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseReservedInstancePool_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        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();
}
