"use strict";
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.8
//   protoc               v4.25.9
// source: io/restorecommerce/token.proto
Object.defineProperty(exports, "__esModule", { value: true });
exports.protoMetadata = exports.TokenServiceDefinition = exports.GrantId = exports.Identifier = exports.TokenData = exports.protobufPackage = void 0;
/* eslint-disable */
const wire_1 = require("@bufbuild/protobuf/wire");
const any_1 = require("../../google/protobuf/any");
const timestamp_1 = require("../../google/protobuf/timestamp");
const auth_1 = require("./auth");
const options_1 = require("./options");
exports.protobufPackage = "io.restorecommerce.token";
function createBaseTokenData() {
    return {};
}
exports.TokenData = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.id !== undefined) {
            writer.uint32(10).string(message.id);
        }
        if (message.payload !== undefined) {
            any_1.Any.encode(message.payload, writer.uint32(18).fork()).join();
        }
        if (message.expiresIn !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.expiresIn), writer.uint32(26).fork()).join();
        }
        if (message.type !== undefined) {
            writer.uint32(34).string(message.type);
        }
        if (message.subject !== undefined) {
            auth_1.Subject.encode(message.subject, writer.uint32(42).fork()).join();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseTokenData();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.payload = any_1.Any.decode(reader, reader.uint32());
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    message.expiresIn = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    continue;
                }
                case 4: {
                    if (tag !== 34) {
                        break;
                    }
                    message.type = reader.string();
                    continue;
                }
                case 5: {
                    if (tag !== 42) {
                        break;
                    }
                    message.subject = auth_1.Subject.decode(reader, reader.uint32());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : undefined,
            payload: isSet(object.payload) ? any_1.Any.fromJSON(object.payload) : undefined,
            expiresIn: isSet(object.expiresIn)
                ? fromJsonTimestamp(object.expiresIn)
                : isSet(object.expires_in)
                    ? fromJsonTimestamp(object.expires_in)
                    : undefined,
            type: isSet(object.type) ? globalThis.String(object.type) : undefined,
            subject: isSet(object.subject) ? auth_1.Subject.fromJSON(object.subject) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined) {
            obj.id = message.id;
        }
        if (message.payload !== undefined) {
            obj.payload = any_1.Any.toJSON(message.payload);
        }
        if (message.expiresIn !== undefined) {
            obj.expiresIn = message.expiresIn.toISOString();
        }
        if (message.type !== undefined) {
            obj.type = message.type;
        }
        if (message.subject !== undefined) {
            obj.subject = auth_1.Subject.toJSON(message.subject);
        }
        return obj;
    },
    create(base) {
        return exports.TokenData.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseTokenData();
        message.id = object.id ?? undefined;
        message.payload = (object.payload !== undefined && object.payload !== null)
            ? any_1.Any.fromPartial(object.payload)
            : undefined;
        message.expiresIn = object.expiresIn ?? undefined;
        message.type = object.type ?? undefined;
        message.subject = (object.subject !== undefined && object.subject !== null)
            ? auth_1.Subject.fromPartial(object.subject)
            : undefined;
        return message;
    },
};
function createBaseIdentifier() {
    return {};
}
exports.Identifier = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.id !== undefined) {
            writer.uint32(10).string(message.id);
        }
        if (message.type !== undefined) {
            writer.uint32(18).string(message.type);
        }
        if (message.subject !== undefined) {
            auth_1.Subject.encode(message.subject, writer.uint32(26).fork()).join();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseIdentifier();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.type = reader.string();
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    message.subject = auth_1.Subject.decode(reader, reader.uint32());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : undefined,
            type: isSet(object.type) ? globalThis.String(object.type) : undefined,
            subject: isSet(object.subject) ? auth_1.Subject.fromJSON(object.subject) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined) {
            obj.id = message.id;
        }
        if (message.type !== undefined) {
            obj.type = message.type;
        }
        if (message.subject !== undefined) {
            obj.subject = auth_1.Subject.toJSON(message.subject);
        }
        return obj;
    },
    create(base) {
        return exports.Identifier.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseIdentifier();
        message.id = object.id ?? undefined;
        message.type = object.type ?? undefined;
        message.subject = (object.subject !== undefined && object.subject !== null)
            ? auth_1.Subject.fromPartial(object.subject)
            : undefined;
        return message;
    },
};
function createBaseGrantId() {
    return {};
}
exports.GrantId = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.grantId !== undefined) {
            writer.uint32(10).string(message.grantId);
        }
        if (message.subject !== undefined) {
            auth_1.Subject.encode(message.subject, writer.uint32(18).fork()).join();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseGrantId();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.grantId = reader.string();
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.subject = auth_1.Subject.decode(reader, reader.uint32());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            grantId: isSet(object.grantId)
                ? globalThis.String(object.grantId)
                : isSet(object.grant_id)
                    ? globalThis.String(object.grant_id)
                    : undefined,
            subject: isSet(object.subject) ? auth_1.Subject.fromJSON(object.subject) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.grantId !== undefined) {
            obj.grantId = message.grantId;
        }
        if (message.subject !== undefined) {
            obj.subject = auth_1.Subject.toJSON(message.subject);
        }
        return obj;
    },
    create(base) {
        return exports.GrantId.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseGrantId();
        message.grantId = object.grantId ?? undefined;
        message.subject = (object.subject !== undefined && object.subject !== null)
            ? auth_1.Subject.fromPartial(object.subject)
            : undefined;
        return message;
    },
};
exports.TokenServiceDefinition = {
    name: "TokenService",
    fullName: "io.restorecommerce.token.TokenService",
    methods: {
        /** creates or upserts ID_token to `Redis` and returns sucess or failure message */
        upsert: {
            name: "upsert",
            requestType: exports.TokenData,
            requestStream: false,
            responseType: any_1.Any,
            responseStream: false,
            options: {},
        },
        find: {
            name: "find",
            requestType: exports.Identifier,
            requestStream: false,
            responseType: any_1.Any,
            responseStream: false,
            options: { _unknownFields: { 248008: [Buffer.from([1])] } },
        },
        /** removes the id_token from redis */
        destroy: {
            name: "destroy",
            requestType: exports.Identifier,
            requestStream: false,
            responseType: any_1.Any,
            responseStream: false,
            options: {},
        },
        /** Destroy/Drop/Remove a stored id_token by its grantId property reference. */
        revokeByGrantId: {
            name: "revokeByGrantId",
            requestType: exports.GrantId,
            requestStream: false,
            responseType: any_1.Any,
            responseStream: false,
            options: {},
        },
        /** Mark a stored id_token as consumed (not yet expired though!). Future finds for this id should be fulfilled with an object containing additional property named "consumed" with a truthy value (timestamp, date, boolean, etc). */
        consume: {
            name: "consume",
            requestType: exports.Identifier,
            requestStream: false,
            responseType: any_1.Any,
            responseStream: false,
            options: {},
        },
    },
};
exports.protoMetadata = {
    fileDescriptor: {
        "name": "io/restorecommerce/token.proto",
        "package": "io.restorecommerce.token",
        "dependency": [
            "io/restorecommerce/auth.proto",
            "google/protobuf/any.proto",
            "io/restorecommerce/options.proto",
            "google/protobuf/timestamp.proto",
        ],
        "publicDependency": [],
        "weakDependency": [],
        "optionDependency": [],
        "messageType": [{
                "name": "TokenData",
                "field": [{
                        "name": "id",
                        "number": 1,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "id",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "payload",
                        "number": 2,
                        "label": 1,
                        "type": 11,
                        "typeName": ".google.protobuf.Any",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "payload",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "expires_in",
                        "number": 3,
                        "label": 1,
                        "type": 11,
                        "typeName": ".google.protobuf.Timestamp",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 2,
                        "jsonName": "expiresIn",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "type",
                        "number": 4,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 3,
                        "jsonName": "type",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "subject",
                        "number": 5,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.auth.Subject",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 4,
                        "jsonName": "subject",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [
                    { "name": "_id", "options": undefined },
                    { "name": "_payload", "options": undefined },
                    { "name": "_expires_in", "options": undefined },
                    { "name": "_type", "options": undefined },
                    { "name": "_subject", "options": undefined },
                ],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "Identifier",
                "field": [{
                        "name": "id",
                        "number": 1,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "id",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "type",
                        "number": 2,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "type",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "subject",
                        "number": 3,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.auth.Subject",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 2,
                        "jsonName": "subject",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_id", "options": undefined }, { "name": "_type", "options": undefined }, {
                        "name": "_subject",
                        "options": undefined,
                    }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "GrantId",
                "field": [{
                        "name": "grant_id",
                        "number": 1,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "grantId",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "subject",
                        "number": 2,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.auth.Subject",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "subject",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_grant_id", "options": undefined }, { "name": "_subject", "options": undefined }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }],
        "enumType": [],
        "service": [{
                "name": "TokenService",
                "method": [{
                        "name": "upsert",
                        "inputType": ".io.restorecommerce.token.TokenData",
                        "outputType": ".google.protobuf.Any",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "find",
                        "inputType": ".io.restorecommerce.token.Identifier",
                        "outputType": ".google.protobuf.Any",
                        "options": { "deprecated": false, "idempotencyLevel": 0, "features": undefined, "uninterpretedOption": [] },
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "destroy",
                        "inputType": ".io.restorecommerce.token.Identifier",
                        "outputType": ".google.protobuf.Any",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "revokeByGrantId",
                        "inputType": ".io.restorecommerce.token.GrantId",
                        "outputType": ".google.protobuf.Any",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "consume",
                        "inputType": ".io.restorecommerce.token.Identifier",
                        "outputType": ".google.protobuf.Any",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }],
                "options": undefined,
            }],
        "extension": [],
        "options": undefined,
        "sourceCodeInfo": {
            "location": [{
                    "path": [6, 0],
                    "span": [12, 0, 20, 1],
                    "leadingComments": "\n Microservice definition.\n",
                    "trailingComments": "",
                    "leadingDetachedComments": [],
                }, {
                    "path": [6, 0, 2, 0],
                    "span": [13, 2, 55],
                    "leadingComments": "",
                    "trailingComments": " creates or upserts ID_token to `Redis` and returns sucess or failure message\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [6, 0, 2, 2],
                    "span": [17, 2, 57],
                    "leadingComments": "",
                    "trailingComments": " removes the id_token from redis\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [6, 0, 2, 3],
                    "span": [18, 2, 62],
                    "leadingComments": "",
                    "trailingComments": " Destroy/Drop/Remove a stored id_token by its grantId property reference.\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [6, 0, 2, 4],
                    "span": [19, 2, 57],
                    "leadingComments": "",
                    "trailingComments": ' Mark a stored id_token as consumed (not yet expired though!). Future finds for this id should be fulfilled with an object containing additional property named "consumed" with a truthy value (timestamp, date, boolean, etc).\n',
                    "leadingDetachedComments": [],
                }],
        },
        "syntax": "proto3",
        "edition": 0,
    },
    references: {
        ".io.restorecommerce.token.TokenData": exports.TokenData,
        ".io.restorecommerce.token.Identifier": exports.Identifier,
        ".io.restorecommerce.token.GrantId": exports.GrantId,
    },
    dependencies: [auth_1.protoMetadata, any_1.protoMetadata, options_1.protoMetadata, timestamp_1.protoMetadata],
    options: { services: { "TokenService": { methods: { "find": { "is_query": true } } } } },
};
function toTimestamp(date) {
    const seconds = Math.trunc(date.getTime() / 1_000);
    const nanos = (date.getTime() % 1_000) * 1_000_000;
    return { seconds, nanos };
}
function fromTimestamp(t) {
    let millis = (t.seconds || 0) * 1_000;
    millis += (t.nanos || 0) / 1_000_000;
    return new globalThis.Date(millis);
}
function fromJsonTimestamp(o) {
    if (o instanceof globalThis.Date) {
        return o;
    }
    else if (typeof o === "string") {
        return new globalThis.Date(o);
    }
    else {
        return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
    }
}
function isSet(value) {
    return value !== null && value !== undefined;
}
//# sourceMappingURL=token.js.map