"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiKey = 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.iam.v1';
const baseApiKey = { id: '', serviceAccountId: '', description: '', scope: '', scopes: '' };
exports.ApiKey = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.serviceAccountId !== '') {
            writer.uint32(18).string(message.serviceAccountId);
        }
        if (message.createdAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(26).fork()).ldelim();
        }
        if (message.description !== '') {
            writer.uint32(34).string(message.description);
        }
        if (message.lastUsedAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.lastUsedAt), writer.uint32(42).fork()).ldelim();
        }
        if (message.scope !== '') {
            writer.uint32(50).string(message.scope);
        }
        for (const v of message.scopes) {
            writer.uint32(66).string(v);
        }
        if (message.expiresAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.expiresAt), writer.uint32(58).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({}, baseApiKey);
        message.scopes = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.serviceAccountId = reader.string();
                    break;
                case 3:
                    message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 4:
                    message.description = reader.string();
                    break;
                case 5:
                    message.lastUsedAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 6:
                    message.scope = reader.string();
                    break;
                case 8:
                    message.scopes.push(reader.string());
                    break;
                case 7:
                    message.expiresAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseApiKey);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.serviceAccountId =
            object.serviceAccountId !== undefined && object.serviceAccountId !== null
                ? String(object.serviceAccountId)
                : '';
        message.createdAt =
            object.createdAt !== undefined && object.createdAt !== null
                ? fromJsonTimestamp(object.createdAt)
                : undefined;
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.lastUsedAt =
            object.lastUsedAt !== undefined && object.lastUsedAt !== null
                ? fromJsonTimestamp(object.lastUsedAt)
                : undefined;
        message.scope =
            object.scope !== undefined && object.scope !== null ? String(object.scope) : '';
        message.scopes = ((_a = object.scopes) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
        message.expiresAt =
            object.expiresAt !== undefined && object.expiresAt !== null
                ? fromJsonTimestamp(object.expiresAt)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.serviceAccountId !== undefined && (obj.serviceAccountId = message.serviceAccountId);
        message.createdAt !== undefined && (obj.createdAt = message.createdAt.toISOString());
        message.description !== undefined && (obj.description = message.description);
        message.lastUsedAt !== undefined && (obj.lastUsedAt = message.lastUsedAt.toISOString());
        message.scope !== undefined && (obj.scope = message.scope);
        if (message.scopes) {
            obj.scopes = message.scopes.map((e) => e);
        }
        else {
            obj.scopes = [];
        }
        message.expiresAt !== undefined && (obj.expiresAt = message.expiresAt.toISOString());
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        const message = Object.assign({}, baseApiKey);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.serviceAccountId = (_b = object.serviceAccountId) !== null && _b !== void 0 ? _b : '';
        message.createdAt = (_c = object.createdAt) !== null && _c !== void 0 ? _c : undefined;
        message.description = (_d = object.description) !== null && _d !== void 0 ? _d : '';
        message.lastUsedAt = (_e = object.lastUsedAt) !== null && _e !== void 0 ? _e : undefined;
        message.scope = (_f = object.scope) !== null && _f !== void 0 ? _f : '';
        message.scopes = ((_g = object.scopes) === null || _g === void 0 ? void 0 : _g.map((e) => e)) || [];
        message.expiresAt = (_h = object.expiresAt) !== null && _h !== void 0 ? _h : undefined;
        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();
}
