"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrivateConnection_StaticRoute = exports.PrivateConnection_LabelsEntry = exports.PrivateConnection = exports.privateConnection_StatusToJSON = exports.privateConnection_StatusFromJSON = exports.PrivateConnection_Status = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const peering_1 = require("../../../../yandex/cloud/cic/v1/peering");
const timestamp_1 = require("../../../../google/protobuf/timestamp");
const wrappers_1 = require("../../../../google/protobuf/wrappers");
exports.protobufPackage = 'yandex.cloud.cic.v1';
var PrivateConnection_Status;
(function (PrivateConnection_Status) {
    PrivateConnection_Status[PrivateConnection_Status["STATUS_UNSPECIFIED"] = 0] = "STATUS_UNSPECIFIED";
    PrivateConnection_Status[PrivateConnection_Status["CREATING"] = 1] = "CREATING";
    PrivateConnection_Status[PrivateConnection_Status["UPDATING"] = 2] = "UPDATING";
    PrivateConnection_Status[PrivateConnection_Status["DELETING"] = 3] = "DELETING";
    PrivateConnection_Status[PrivateConnection_Status["ACTIVE"] = 4] = "ACTIVE";
    PrivateConnection_Status[PrivateConnection_Status["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(PrivateConnection_Status = exports.PrivateConnection_Status || (exports.PrivateConnection_Status = {}));
function privateConnection_StatusFromJSON(object) {
    switch (object) {
        case 0:
        case 'STATUS_UNSPECIFIED':
            return PrivateConnection_Status.STATUS_UNSPECIFIED;
        case 1:
        case 'CREATING':
            return PrivateConnection_Status.CREATING;
        case 2:
        case 'UPDATING':
            return PrivateConnection_Status.UPDATING;
        case 3:
        case 'DELETING':
            return PrivateConnection_Status.DELETING;
        case 4:
        case 'ACTIVE':
            return PrivateConnection_Status.ACTIVE;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return PrivateConnection_Status.UNRECOGNIZED;
    }
}
exports.privateConnection_StatusFromJSON = privateConnection_StatusFromJSON;
function privateConnection_StatusToJSON(object) {
    switch (object) {
        case PrivateConnection_Status.STATUS_UNSPECIFIED:
            return 'STATUS_UNSPECIFIED';
        case PrivateConnection_Status.CREATING:
            return 'CREATING';
        case PrivateConnection_Status.UPDATING:
            return 'UPDATING';
        case PrivateConnection_Status.DELETING:
            return 'DELETING';
        case PrivateConnection_Status.ACTIVE:
            return 'ACTIVE';
        default:
            return 'UNKNOWN';
    }
}
exports.privateConnection_StatusToJSON = privateConnection_StatusToJSON;
const basePrivateConnection = {
    id: '',
    name: '',
    description: '',
    folderId: '',
    regionId: '',
    trunkConnectionId: '',
    status: 0,
};
exports.PrivateConnection = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.name !== '') {
            writer.uint32(18).string(message.name);
        }
        if (message.description !== '') {
            writer.uint32(26).string(message.description);
        }
        if (message.folderId !== '') {
            writer.uint32(42).string(message.folderId);
        }
        if (message.regionId !== '') {
            writer.uint32(50).string(message.regionId);
        }
        if (message.trunkConnectionId !== '') {
            writer.uint32(58).string(message.trunkConnectionId);
        }
        if (message.vlanId !== undefined) {
            wrappers_1.Int64Value.encode({ value: message.vlanId }, writer.uint32(66).fork()).ldelim();
        }
        if (message.ipv4Peering !== undefined) {
            peering_1.Peering.encode(message.ipv4Peering, writer.uint32(74).fork()).ldelim();
        }
        for (const v of message.ipv4StaticRoutes) {
            exports.PrivateConnection_StaticRoute.encode(v, writer.uint32(146).fork()).ldelim();
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.PrivateConnection_LabelsEntry.encode({ key: key, value }, writer.uint32(194).fork()).ldelim();
        });
        if (message.status !== 0) {
            writer.uint32(200).int32(message.status);
        }
        if (message.createdAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(218).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({}, basePrivateConnection);
        message.ipv4StaticRoutes = [];
        message.labels = {};
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.name = reader.string();
                    break;
                case 3:
                    message.description = reader.string();
                    break;
                case 5:
                    message.folderId = reader.string();
                    break;
                case 6:
                    message.regionId = reader.string();
                    break;
                case 7:
                    message.trunkConnectionId = reader.string();
                    break;
                case 8:
                    message.vlanId = wrappers_1.Int64Value.decode(reader, reader.uint32()).value;
                    break;
                case 9:
                    message.ipv4Peering = peering_1.Peering.decode(reader, reader.uint32());
                    break;
                case 18:
                    message.ipv4StaticRoutes.push(exports.PrivateConnection_StaticRoute.decode(reader, reader.uint32()));
                    break;
                case 24:
                    const entry24 = exports.PrivateConnection_LabelsEntry.decode(reader, reader.uint32());
                    if (entry24.value !== undefined) {
                        message.labels[entry24.key] = entry24.value;
                    }
                    break;
                case 25:
                    message.status = reader.int32();
                    break;
                case 27:
                    message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, basePrivateConnection);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.folderId =
            object.folderId !== undefined && object.folderId !== null
                ? String(object.folderId)
                : '';
        message.regionId =
            object.regionId !== undefined && object.regionId !== null
                ? String(object.regionId)
                : '';
        message.trunkConnectionId =
            object.trunkConnectionId !== undefined && object.trunkConnectionId !== null
                ? String(object.trunkConnectionId)
                : '';
        message.vlanId =
            object.vlanId !== undefined && object.vlanId !== null
                ? Number(object.vlanId)
                : undefined;
        message.ipv4Peering =
            object.ipv4Peering !== undefined && object.ipv4Peering !== null
                ? peering_1.Peering.fromJSON(object.ipv4Peering)
                : undefined;
        message.ipv4StaticRoutes = ((_a = object.ipv4StaticRoutes) !== null && _a !== void 0 ? _a : []).map((e) => exports.PrivateConnection_StaticRoute.fromJSON(e));
        message.labels = Object.entries((_b = object.labels) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.status =
            object.status !== undefined && object.status !== null
                ? privateConnection_StatusFromJSON(object.status)
                : 0;
        message.createdAt =
            object.createdAt !== undefined && object.createdAt !== null
                ? fromJsonTimestamp(object.createdAt)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.name !== undefined && (obj.name = message.name);
        message.description !== undefined && (obj.description = message.description);
        message.folderId !== undefined && (obj.folderId = message.folderId);
        message.regionId !== undefined && (obj.regionId = message.regionId);
        message.trunkConnectionId !== undefined &&
            (obj.trunkConnectionId = message.trunkConnectionId);
        message.vlanId !== undefined && (obj.vlanId = message.vlanId);
        message.ipv4Peering !== undefined &&
            (obj.ipv4Peering = message.ipv4Peering
                ? peering_1.Peering.toJSON(message.ipv4Peering)
                : undefined);
        if (message.ipv4StaticRoutes) {
            obj.ipv4StaticRoutes = message.ipv4StaticRoutes.map((e) => e ? exports.PrivateConnection_StaticRoute.toJSON(e) : undefined);
        }
        else {
            obj.ipv4StaticRoutes = [];
        }
        obj.labels = {};
        if (message.labels) {
            Object.entries(message.labels).forEach(([k, v]) => {
                obj.labels[k] = v;
            });
        }
        message.status !== undefined &&
            (obj.status = privateConnection_StatusToJSON(message.status));
        message.createdAt !== undefined && (obj.createdAt = message.createdAt.toISOString());
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
        const message = Object.assign({}, basePrivateConnection);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.name = (_b = object.name) !== null && _b !== void 0 ? _b : '';
        message.description = (_c = object.description) !== null && _c !== void 0 ? _c : '';
        message.folderId = (_d = object.folderId) !== null && _d !== void 0 ? _d : '';
        message.regionId = (_e = object.regionId) !== null && _e !== void 0 ? _e : '';
        message.trunkConnectionId = (_f = object.trunkConnectionId) !== null && _f !== void 0 ? _f : '';
        message.vlanId = (_g = object.vlanId) !== null && _g !== void 0 ? _g : undefined;
        message.ipv4Peering =
            object.ipv4Peering !== undefined && object.ipv4Peering !== null
                ? peering_1.Peering.fromPartial(object.ipv4Peering)
                : undefined;
        message.ipv4StaticRoutes =
            ((_h = object.ipv4StaticRoutes) === null || _h === void 0 ? void 0 : _h.map((e) => exports.PrivateConnection_StaticRoute.fromPartial(e))) || [];
        message.labels = Object.entries((_j = object.labels) !== null && _j !== void 0 ? _j : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.status = (_k = object.status) !== null && _k !== void 0 ? _k : 0;
        message.createdAt = (_l = object.createdAt) !== null && _l !== void 0 ? _l : undefined;
        return message;
    },
};
const basePrivateConnection_LabelsEntry = { key: '', value: '' };
exports.PrivateConnection_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({}, basePrivateConnection_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({}, basePrivateConnection_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({}, basePrivateConnection_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const basePrivateConnection_StaticRoute = { prefix: '' };
exports.PrivateConnection_StaticRoute = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.prefix !== '') {
            writer.uint32(10).string(message.prefix);
        }
        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({}, basePrivateConnection_StaticRoute);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.prefix = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, basePrivateConnection_StaticRoute);
        message.prefix =
            object.prefix !== undefined && object.prefix !== null ? String(object.prefix) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.prefix !== undefined && (obj.prefix = message.prefix);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, basePrivateConnection_StaticRoute);
        message.prefix = (_a = object.prefix) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
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));
    }
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
