// @generated by protobuf-ts 2.11.1 with parameter long_type_string,ts_nocheck
// @generated from protobuf file "runtime/v1/grant.proto" (package "nimi.runtime.v1", syntax proto3)
// tslint:disable
// @ts-nocheck
import { Ack } from "./common.js";
import { ServiceType } from "@protobuf-ts/runtime-rpc";
import { WireType } from "@protobuf-ts/runtime";
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
import { reflectionMergePartial } from "@protobuf-ts/runtime";
import { MessageType } from "@protobuf-ts/runtime";
import { ReasonCode } from "./common.js";
import { ConsentRef } from "./common.js";
import { ResourceSelectors } from "./common.js";
import { Timestamp } from "../../google/protobuf/timestamp.js";
import { ExternalPrincipalType } from "./common.js";
/**
 * @generated from protobuf enum nimi.runtime.v1.PolicyMode
 */
export var PolicyMode;
(function (PolicyMode) {
    /**
     * @generated from protobuf enum value: POLICY_MODE_UNSPECIFIED = 0;
     */
    PolicyMode[PolicyMode["UNSPECIFIED"] = 0] = "UNSPECIFIED";
    /**
     * @generated from protobuf enum value: POLICY_MODE_PRESET = 1;
     */
    PolicyMode[PolicyMode["PRESET"] = 1] = "PRESET";
    /**
     * @generated from protobuf enum value: POLICY_MODE_CUSTOM = 2;
     */
    PolicyMode[PolicyMode["CUSTOM"] = 2] = "CUSTOM";
})(PolicyMode || (PolicyMode = {}));
/**
 * @generated from protobuf enum nimi.runtime.v1.AuthorizationPreset
 */
export var AuthorizationPreset;
(function (AuthorizationPreset) {
    /**
     * @generated from protobuf enum value: AUTHORIZATION_PRESET_UNSPECIFIED = 0;
     */
    AuthorizationPreset[AuthorizationPreset["UNSPECIFIED"] = 0] = "UNSPECIFIED";
    /**
     * @generated from protobuf enum value: AUTHORIZATION_PRESET_READ_ONLY = 1;
     */
    AuthorizationPreset[AuthorizationPreset["READ_ONLY"] = 1] = "READ_ONLY";
    /**
     * @generated from protobuf enum value: AUTHORIZATION_PRESET_FULL = 2;
     */
    AuthorizationPreset[AuthorizationPreset["FULL"] = 2] = "FULL";
    /**
     * @generated from protobuf enum value: AUTHORIZATION_PRESET_DELEGATE = 3;
     */
    AuthorizationPreset[AuthorizationPreset["DELEGATE"] = 3] = "DELEGATE";
})(AuthorizationPreset || (AuthorizationPreset = {}));
// @generated message type with reflection information, may provide speed optimized methods
class AuthorizeExternalPrincipalRequest$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.AuthorizeExternalPrincipalRequest", [
            { no: 1, name: "domain", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "app_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "external_principal_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 4, name: "external_principal_type", kind: "enum", T: () => ["nimi.runtime.v1.ExternalPrincipalType", ExternalPrincipalType, "EXTERNAL_PRINCIPAL_TYPE_"] },
            { no: 5, name: "subject_user_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 6, name: "consent_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 7, name: "consent_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 8, name: "decision_at", kind: "message", T: () => Timestamp },
            { no: 9, name: "policy_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 10, name: "policy_mode", kind: "enum", T: () => ["nimi.runtime.v1.PolicyMode", PolicyMode, "POLICY_MODE_"] },
            { no: 11, name: "preset", kind: "enum", T: () => ["nimi.runtime.v1.AuthorizationPreset", AuthorizationPreset, "AUTHORIZATION_PRESET_"] },
            { no: 12, name: "scopes", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
            { no: 13, name: "resource_selectors", kind: "message", T: () => ResourceSelectors },
            { no: 14, name: "can_delegate", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
            { no: 15, name: "max_delegation_depth", kind: "scalar", T: 5 /*ScalarType.INT32*/ },
            { no: 16, name: "ttl_seconds", kind: "scalar", T: 5 /*ScalarType.INT32*/ },
            { no: 17, name: "scope_catalog_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 18, name: "policy_override", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.domain = "";
        message.appId = "";
        message.externalPrincipalId = "";
        message.externalPrincipalType = 0;
        message.subjectUserId = "";
        message.consentId = "";
        message.consentVersion = "";
        message.policyVersion = "";
        message.policyMode = 0;
        message.preset = 0;
        message.scopes = [];
        message.canDelegate = false;
        message.maxDelegationDepth = 0;
        message.ttlSeconds = 0;
        message.scopeCatalogVersion = "";
        message.policyOverride = false;
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string domain */ 1:
                    message.domain = reader.string();
                    break;
                case /* string app_id */ 2:
                    message.appId = reader.string();
                    break;
                case /* string external_principal_id */ 3:
                    message.externalPrincipalId = reader.string();
                    break;
                case /* nimi.runtime.v1.ExternalPrincipalType external_principal_type */ 4:
                    message.externalPrincipalType = reader.int32();
                    break;
                case /* string subject_user_id */ 5:
                    message.subjectUserId = reader.string();
                    break;
                case /* string consent_id */ 6:
                    message.consentId = reader.string();
                    break;
                case /* string consent_version */ 7:
                    message.consentVersion = reader.string();
                    break;
                case /* google.protobuf.Timestamp decision_at */ 8:
                    message.decisionAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.decisionAt);
                    break;
                case /* string policy_version */ 9:
                    message.policyVersion = reader.string();
                    break;
                case /* nimi.runtime.v1.PolicyMode policy_mode */ 10:
                    message.policyMode = reader.int32();
                    break;
                case /* nimi.runtime.v1.AuthorizationPreset preset */ 11:
                    message.preset = reader.int32();
                    break;
                case /* repeated string scopes */ 12:
                    message.scopes.push(reader.string());
                    break;
                case /* nimi.runtime.v1.ResourceSelectors resource_selectors */ 13:
                    message.resourceSelectors = ResourceSelectors.internalBinaryRead(reader, reader.uint32(), options, message.resourceSelectors);
                    break;
                case /* bool can_delegate */ 14:
                    message.canDelegate = reader.bool();
                    break;
                case /* int32 max_delegation_depth */ 15:
                    message.maxDelegationDepth = reader.int32();
                    break;
                case /* int32 ttl_seconds */ 16:
                    message.ttlSeconds = reader.int32();
                    break;
                case /* string scope_catalog_version */ 17:
                    message.scopeCatalogVersion = reader.string();
                    break;
                case /* bool policy_override */ 18:
                    message.policyOverride = reader.bool();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string domain = 1; */
        if (message.domain !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.domain);
        /* string app_id = 2; */
        if (message.appId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.appId);
        /* string external_principal_id = 3; */
        if (message.externalPrincipalId !== "")
            writer.tag(3, WireType.LengthDelimited).string(message.externalPrincipalId);
        /* nimi.runtime.v1.ExternalPrincipalType external_principal_type = 4; */
        if (message.externalPrincipalType !== 0)
            writer.tag(4, WireType.Varint).int32(message.externalPrincipalType);
        /* string subject_user_id = 5; */
        if (message.subjectUserId !== "")
            writer.tag(5, WireType.LengthDelimited).string(message.subjectUserId);
        /* string consent_id = 6; */
        if (message.consentId !== "")
            writer.tag(6, WireType.LengthDelimited).string(message.consentId);
        /* string consent_version = 7; */
        if (message.consentVersion !== "")
            writer.tag(7, WireType.LengthDelimited).string(message.consentVersion);
        /* google.protobuf.Timestamp decision_at = 8; */
        if (message.decisionAt)
            Timestamp.internalBinaryWrite(message.decisionAt, writer.tag(8, WireType.LengthDelimited).fork(), options).join();
        /* string policy_version = 9; */
        if (message.policyVersion !== "")
            writer.tag(9, WireType.LengthDelimited).string(message.policyVersion);
        /* nimi.runtime.v1.PolicyMode policy_mode = 10; */
        if (message.policyMode !== 0)
            writer.tag(10, WireType.Varint).int32(message.policyMode);
        /* nimi.runtime.v1.AuthorizationPreset preset = 11; */
        if (message.preset !== 0)
            writer.tag(11, WireType.Varint).int32(message.preset);
        /* repeated string scopes = 12; */
        for (let i = 0; i < message.scopes.length; i++)
            writer.tag(12, WireType.LengthDelimited).string(message.scopes[i]);
        /* nimi.runtime.v1.ResourceSelectors resource_selectors = 13; */
        if (message.resourceSelectors)
            ResourceSelectors.internalBinaryWrite(message.resourceSelectors, writer.tag(13, WireType.LengthDelimited).fork(), options).join();
        /* bool can_delegate = 14; */
        if (message.canDelegate !== false)
            writer.tag(14, WireType.Varint).bool(message.canDelegate);
        /* int32 max_delegation_depth = 15; */
        if (message.maxDelegationDepth !== 0)
            writer.tag(15, WireType.Varint).int32(message.maxDelegationDepth);
        /* int32 ttl_seconds = 16; */
        if (message.ttlSeconds !== 0)
            writer.tag(16, WireType.Varint).int32(message.ttlSeconds);
        /* string scope_catalog_version = 17; */
        if (message.scopeCatalogVersion !== "")
            writer.tag(17, WireType.LengthDelimited).string(message.scopeCatalogVersion);
        /* bool policy_override = 18; */
        if (message.policyOverride !== false)
            writer.tag(18, WireType.Varint).bool(message.policyOverride);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.AuthorizeExternalPrincipalRequest
 */
export const AuthorizeExternalPrincipalRequest = new AuthorizeExternalPrincipalRequest$Type();
// @generated message type with reflection information, may provide speed optimized methods
class AuthorizeExternalPrincipalResponse$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.AuthorizeExternalPrincipalResponse", [
            { no: 1, name: "token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "app_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "subject_user_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 4, name: "external_principal_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 5, name: "effective_scopes", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
            { no: 6, name: "resource_selectors", kind: "message", T: () => ResourceSelectors },
            { no: 7, name: "consent_ref", kind: "message", T: () => ConsentRef },
            { no: 8, name: "policy_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 9, name: "issued_scope_catalog_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 10, name: "can_delegate", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
            { no: 11, name: "expires_at", kind: "message", T: () => Timestamp },
            { no: 12, name: "secret", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.tokenId = "";
        message.appId = "";
        message.subjectUserId = "";
        message.externalPrincipalId = "";
        message.effectiveScopes = [];
        message.policyVersion = "";
        message.issuedScopeCatalogVersion = "";
        message.canDelegate = false;
        message.secret = "";
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string token_id */ 1:
                    message.tokenId = reader.string();
                    break;
                case /* string app_id */ 2:
                    message.appId = reader.string();
                    break;
                case /* string subject_user_id */ 3:
                    message.subjectUserId = reader.string();
                    break;
                case /* string external_principal_id */ 4:
                    message.externalPrincipalId = reader.string();
                    break;
                case /* repeated string effective_scopes */ 5:
                    message.effectiveScopes.push(reader.string());
                    break;
                case /* nimi.runtime.v1.ResourceSelectors resource_selectors */ 6:
                    message.resourceSelectors = ResourceSelectors.internalBinaryRead(reader, reader.uint32(), options, message.resourceSelectors);
                    break;
                case /* nimi.runtime.v1.ConsentRef consent_ref */ 7:
                    message.consentRef = ConsentRef.internalBinaryRead(reader, reader.uint32(), options, message.consentRef);
                    break;
                case /* string policy_version */ 8:
                    message.policyVersion = reader.string();
                    break;
                case /* string issued_scope_catalog_version */ 9:
                    message.issuedScopeCatalogVersion = reader.string();
                    break;
                case /* bool can_delegate */ 10:
                    message.canDelegate = reader.bool();
                    break;
                case /* google.protobuf.Timestamp expires_at */ 11:
                    message.expiresAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.expiresAt);
                    break;
                case /* string secret */ 12:
                    message.secret = reader.string();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string token_id = 1; */
        if (message.tokenId !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.tokenId);
        /* string app_id = 2; */
        if (message.appId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.appId);
        /* string subject_user_id = 3; */
        if (message.subjectUserId !== "")
            writer.tag(3, WireType.LengthDelimited).string(message.subjectUserId);
        /* string external_principal_id = 4; */
        if (message.externalPrincipalId !== "")
            writer.tag(4, WireType.LengthDelimited).string(message.externalPrincipalId);
        /* repeated string effective_scopes = 5; */
        for (let i = 0; i < message.effectiveScopes.length; i++)
            writer.tag(5, WireType.LengthDelimited).string(message.effectiveScopes[i]);
        /* nimi.runtime.v1.ResourceSelectors resource_selectors = 6; */
        if (message.resourceSelectors)
            ResourceSelectors.internalBinaryWrite(message.resourceSelectors, writer.tag(6, WireType.LengthDelimited).fork(), options).join();
        /* nimi.runtime.v1.ConsentRef consent_ref = 7; */
        if (message.consentRef)
            ConsentRef.internalBinaryWrite(message.consentRef, writer.tag(7, WireType.LengthDelimited).fork(), options).join();
        /* string policy_version = 8; */
        if (message.policyVersion !== "")
            writer.tag(8, WireType.LengthDelimited).string(message.policyVersion);
        /* string issued_scope_catalog_version = 9; */
        if (message.issuedScopeCatalogVersion !== "")
            writer.tag(9, WireType.LengthDelimited).string(message.issuedScopeCatalogVersion);
        /* bool can_delegate = 10; */
        if (message.canDelegate !== false)
            writer.tag(10, WireType.Varint).bool(message.canDelegate);
        /* google.protobuf.Timestamp expires_at = 11; */
        if (message.expiresAt)
            Timestamp.internalBinaryWrite(message.expiresAt, writer.tag(11, WireType.LengthDelimited).fork(), options).join();
        /* string secret = 12; */
        if (message.secret !== "")
            writer.tag(12, WireType.LengthDelimited).string(message.secret);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.AuthorizeExternalPrincipalResponse
 */
export const AuthorizeExternalPrincipalResponse = new AuthorizeExternalPrincipalResponse$Type();
// @generated message type with reflection information, may provide speed optimized methods
class ValidateAppAccessTokenRequest$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.ValidateAppAccessTokenRequest", [
            { no: 1, name: "app_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "subject_user_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 4, name: "operation", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 5, name: "requested_scopes", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
            { no: 6, name: "resource_selectors", kind: "message", T: () => ResourceSelectors }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.appId = "";
        message.tokenId = "";
        message.subjectUserId = "";
        message.operation = "";
        message.requestedScopes = [];
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string app_id */ 1:
                    message.appId = reader.string();
                    break;
                case /* string token_id */ 2:
                    message.tokenId = reader.string();
                    break;
                case /* string subject_user_id */ 3:
                    message.subjectUserId = reader.string();
                    break;
                case /* string operation */ 4:
                    message.operation = reader.string();
                    break;
                case /* repeated string requested_scopes */ 5:
                    message.requestedScopes.push(reader.string());
                    break;
                case /* nimi.runtime.v1.ResourceSelectors resource_selectors */ 6:
                    message.resourceSelectors = ResourceSelectors.internalBinaryRead(reader, reader.uint32(), options, message.resourceSelectors);
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string app_id = 1; */
        if (message.appId !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.appId);
        /* string token_id = 2; */
        if (message.tokenId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.tokenId);
        /* string subject_user_id = 3; */
        if (message.subjectUserId !== "")
            writer.tag(3, WireType.LengthDelimited).string(message.subjectUserId);
        /* string operation = 4; */
        if (message.operation !== "")
            writer.tag(4, WireType.LengthDelimited).string(message.operation);
        /* repeated string requested_scopes = 5; */
        for (let i = 0; i < message.requestedScopes.length; i++)
            writer.tag(5, WireType.LengthDelimited).string(message.requestedScopes[i]);
        /* nimi.runtime.v1.ResourceSelectors resource_selectors = 6; */
        if (message.resourceSelectors)
            ResourceSelectors.internalBinaryWrite(message.resourceSelectors, writer.tag(6, WireType.LengthDelimited).fork(), options).join();
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.ValidateAppAccessTokenRequest
 */
export const ValidateAppAccessTokenRequest = new ValidateAppAccessTokenRequest$Type();
// @generated message type with reflection information, may provide speed optimized methods
class ValidateAppAccessTokenResponse$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.ValidateAppAccessTokenResponse", [
            { no: 1, name: "valid", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
            { no: 2, name: "reason_code", kind: "enum", T: () => ["nimi.runtime.v1.ReasonCode", ReasonCode] },
            { no: 3, name: "effective_scopes", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
            { no: 4, name: "policy_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 5, name: "issued_scope_catalog_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 6, name: "action_hint", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.valid = false;
        message.reasonCode = 0;
        message.effectiveScopes = [];
        message.policyVersion = "";
        message.issuedScopeCatalogVersion = "";
        message.actionHint = "";
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* bool valid */ 1:
                    message.valid = reader.bool();
                    break;
                case /* nimi.runtime.v1.ReasonCode reason_code */ 2:
                    message.reasonCode = reader.int32();
                    break;
                case /* repeated string effective_scopes */ 3:
                    message.effectiveScopes.push(reader.string());
                    break;
                case /* string policy_version */ 4:
                    message.policyVersion = reader.string();
                    break;
                case /* string issued_scope_catalog_version */ 5:
                    message.issuedScopeCatalogVersion = reader.string();
                    break;
                case /* string action_hint */ 6:
                    message.actionHint = reader.string();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* bool valid = 1; */
        if (message.valid !== false)
            writer.tag(1, WireType.Varint).bool(message.valid);
        /* nimi.runtime.v1.ReasonCode reason_code = 2; */
        if (message.reasonCode !== 0)
            writer.tag(2, WireType.Varint).int32(message.reasonCode);
        /* repeated string effective_scopes = 3; */
        for (let i = 0; i < message.effectiveScopes.length; i++)
            writer.tag(3, WireType.LengthDelimited).string(message.effectiveScopes[i]);
        /* string policy_version = 4; */
        if (message.policyVersion !== "")
            writer.tag(4, WireType.LengthDelimited).string(message.policyVersion);
        /* string issued_scope_catalog_version = 5; */
        if (message.issuedScopeCatalogVersion !== "")
            writer.tag(5, WireType.LengthDelimited).string(message.issuedScopeCatalogVersion);
        /* string action_hint = 6; */
        if (message.actionHint !== "")
            writer.tag(6, WireType.LengthDelimited).string(message.actionHint);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.ValidateAppAccessTokenResponse
 */
export const ValidateAppAccessTokenResponse = new ValidateAppAccessTokenResponse$Type();
// @generated message type with reflection information, may provide speed optimized methods
class RevokeAppAccessTokenRequest$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.RevokeAppAccessTokenRequest", [
            { no: 1, name: "app_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.appId = "";
        message.tokenId = "";
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string app_id */ 1:
                    message.appId = reader.string();
                    break;
                case /* string token_id */ 2:
                    message.tokenId = reader.string();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string app_id = 1; */
        if (message.appId !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.appId);
        /* string token_id = 2; */
        if (message.tokenId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.tokenId);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.RevokeAppAccessTokenRequest
 */
export const RevokeAppAccessTokenRequest = new RevokeAppAccessTokenRequest$Type();
// @generated message type with reflection information, may provide speed optimized methods
class IssueDelegatedAccessTokenRequest$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.IssueDelegatedAccessTokenRequest", [
            { no: 1, name: "app_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "parent_token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "scopes", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
            { no: 4, name: "resource_selectors", kind: "message", T: () => ResourceSelectors },
            { no: 5, name: "ttl_seconds", kind: "scalar", T: 5 /*ScalarType.INT32*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.appId = "";
        message.parentTokenId = "";
        message.scopes = [];
        message.ttlSeconds = 0;
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string app_id */ 1:
                    message.appId = reader.string();
                    break;
                case /* string parent_token_id */ 2:
                    message.parentTokenId = reader.string();
                    break;
                case /* repeated string scopes */ 3:
                    message.scopes.push(reader.string());
                    break;
                case /* nimi.runtime.v1.ResourceSelectors resource_selectors */ 4:
                    message.resourceSelectors = ResourceSelectors.internalBinaryRead(reader, reader.uint32(), options, message.resourceSelectors);
                    break;
                case /* int32 ttl_seconds */ 5:
                    message.ttlSeconds = reader.int32();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string app_id = 1; */
        if (message.appId !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.appId);
        /* string parent_token_id = 2; */
        if (message.parentTokenId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.parentTokenId);
        /* repeated string scopes = 3; */
        for (let i = 0; i < message.scopes.length; i++)
            writer.tag(3, WireType.LengthDelimited).string(message.scopes[i]);
        /* nimi.runtime.v1.ResourceSelectors resource_selectors = 4; */
        if (message.resourceSelectors)
            ResourceSelectors.internalBinaryWrite(message.resourceSelectors, writer.tag(4, WireType.LengthDelimited).fork(), options).join();
        /* int32 ttl_seconds = 5; */
        if (message.ttlSeconds !== 0)
            writer.tag(5, WireType.Varint).int32(message.ttlSeconds);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.IssueDelegatedAccessTokenRequest
 */
export const IssueDelegatedAccessTokenRequest = new IssueDelegatedAccessTokenRequest$Type();
// @generated message type with reflection information, may provide speed optimized methods
class IssueDelegatedAccessTokenResponse$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.IssueDelegatedAccessTokenResponse", [
            { no: 1, name: "token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "parent_token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "effective_scopes", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
            { no: 4, name: "expires_at", kind: "message", T: () => Timestamp },
            { no: 5, name: "secret", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.tokenId = "";
        message.parentTokenId = "";
        message.effectiveScopes = [];
        message.secret = "";
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string token_id */ 1:
                    message.tokenId = reader.string();
                    break;
                case /* string parent_token_id */ 2:
                    message.parentTokenId = reader.string();
                    break;
                case /* repeated string effective_scopes */ 3:
                    message.effectiveScopes.push(reader.string());
                    break;
                case /* google.protobuf.Timestamp expires_at */ 4:
                    message.expiresAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.expiresAt);
                    break;
                case /* string secret */ 5:
                    message.secret = reader.string();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string token_id = 1; */
        if (message.tokenId !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.tokenId);
        /* string parent_token_id = 2; */
        if (message.parentTokenId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.parentTokenId);
        /* repeated string effective_scopes = 3; */
        for (let i = 0; i < message.effectiveScopes.length; i++)
            writer.tag(3, WireType.LengthDelimited).string(message.effectiveScopes[i]);
        /* google.protobuf.Timestamp expires_at = 4; */
        if (message.expiresAt)
            Timestamp.internalBinaryWrite(message.expiresAt, writer.tag(4, WireType.LengthDelimited).fork(), options).join();
        /* string secret = 5; */
        if (message.secret !== "")
            writer.tag(5, WireType.LengthDelimited).string(message.secret);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.IssueDelegatedAccessTokenResponse
 */
export const IssueDelegatedAccessTokenResponse = new IssueDelegatedAccessTokenResponse$Type();
// @generated message type with reflection information, may provide speed optimized methods
class ListTokenChainRequest$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.ListTokenChainRequest", [
            { no: 1, name: "app_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "root_token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "include_revoked", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
            { no: 4, name: "page_size", kind: "scalar", T: 5 /*ScalarType.INT32*/ },
            { no: 5, name: "page_token", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.appId = "";
        message.rootTokenId = "";
        message.includeRevoked = false;
        message.pageSize = 0;
        message.pageToken = "";
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string app_id */ 1:
                    message.appId = reader.string();
                    break;
                case /* string root_token_id */ 2:
                    message.rootTokenId = reader.string();
                    break;
                case /* bool include_revoked */ 3:
                    message.includeRevoked = reader.bool();
                    break;
                case /* int32 page_size */ 4:
                    message.pageSize = reader.int32();
                    break;
                case /* string page_token */ 5:
                    message.pageToken = reader.string();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string app_id = 1; */
        if (message.appId !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.appId);
        /* string root_token_id = 2; */
        if (message.rootTokenId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.rootTokenId);
        /* bool include_revoked = 3; */
        if (message.includeRevoked !== false)
            writer.tag(3, WireType.Varint).bool(message.includeRevoked);
        /* int32 page_size = 4; */
        if (message.pageSize !== 0)
            writer.tag(4, WireType.Varint).int32(message.pageSize);
        /* string page_token = 5; */
        if (message.pageToken !== "")
            writer.tag(5, WireType.LengthDelimited).string(message.pageToken);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.ListTokenChainRequest
 */
export const ListTokenChainRequest = new ListTokenChainRequest$Type();
// @generated message type with reflection information, may provide speed optimized methods
class TokenChainEntry$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.TokenChainEntry", [
            { no: 1, name: "token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 2, name: "parent_token_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "principal_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 4, name: "principal_type", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 5, name: "effective_scopes", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
            { no: 6, name: "issued_at", kind: "message", T: () => Timestamp },
            { no: 7, name: "expires_at", kind: "message", T: () => Timestamp },
            { no: 8, name: "revoked", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
            { no: 9, name: "delegation_depth", kind: "scalar", T: 5 /*ScalarType.INT32*/ },
            { no: 10, name: "policy_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 11, name: "issued_scope_catalog_version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.tokenId = "";
        message.parentTokenId = "";
        message.principalId = "";
        message.principalType = "";
        message.effectiveScopes = [];
        message.revoked = false;
        message.delegationDepth = 0;
        message.policyVersion = "";
        message.issuedScopeCatalogVersion = "";
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* string token_id */ 1:
                    message.tokenId = reader.string();
                    break;
                case /* string parent_token_id */ 2:
                    message.parentTokenId = reader.string();
                    break;
                case /* string principal_id */ 3:
                    message.principalId = reader.string();
                    break;
                case /* string principal_type */ 4:
                    message.principalType = reader.string();
                    break;
                case /* repeated string effective_scopes */ 5:
                    message.effectiveScopes.push(reader.string());
                    break;
                case /* google.protobuf.Timestamp issued_at */ 6:
                    message.issuedAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.issuedAt);
                    break;
                case /* google.protobuf.Timestamp expires_at */ 7:
                    message.expiresAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.expiresAt);
                    break;
                case /* bool revoked */ 8:
                    message.revoked = reader.bool();
                    break;
                case /* int32 delegation_depth */ 9:
                    message.delegationDepth = reader.int32();
                    break;
                case /* string policy_version */ 10:
                    message.policyVersion = reader.string();
                    break;
                case /* string issued_scope_catalog_version */ 11:
                    message.issuedScopeCatalogVersion = reader.string();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* string token_id = 1; */
        if (message.tokenId !== "")
            writer.tag(1, WireType.LengthDelimited).string(message.tokenId);
        /* string parent_token_id = 2; */
        if (message.parentTokenId !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.parentTokenId);
        /* string principal_id = 3; */
        if (message.principalId !== "")
            writer.tag(3, WireType.LengthDelimited).string(message.principalId);
        /* string principal_type = 4; */
        if (message.principalType !== "")
            writer.tag(4, WireType.LengthDelimited).string(message.principalType);
        /* repeated string effective_scopes = 5; */
        for (let i = 0; i < message.effectiveScopes.length; i++)
            writer.tag(5, WireType.LengthDelimited).string(message.effectiveScopes[i]);
        /* google.protobuf.Timestamp issued_at = 6; */
        if (message.issuedAt)
            Timestamp.internalBinaryWrite(message.issuedAt, writer.tag(6, WireType.LengthDelimited).fork(), options).join();
        /* google.protobuf.Timestamp expires_at = 7; */
        if (message.expiresAt)
            Timestamp.internalBinaryWrite(message.expiresAt, writer.tag(7, WireType.LengthDelimited).fork(), options).join();
        /* bool revoked = 8; */
        if (message.revoked !== false)
            writer.tag(8, WireType.Varint).bool(message.revoked);
        /* int32 delegation_depth = 9; */
        if (message.delegationDepth !== 0)
            writer.tag(9, WireType.Varint).int32(message.delegationDepth);
        /* string policy_version = 10; */
        if (message.policyVersion !== "")
            writer.tag(10, WireType.LengthDelimited).string(message.policyVersion);
        /* string issued_scope_catalog_version = 11; */
        if (message.issuedScopeCatalogVersion !== "")
            writer.tag(11, WireType.LengthDelimited).string(message.issuedScopeCatalogVersion);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.TokenChainEntry
 */
export const TokenChainEntry = new TokenChainEntry$Type();
// @generated message type with reflection information, may provide speed optimized methods
class ListTokenChainResponse$Type extends MessageType {
    constructor() {
        super("nimi.runtime.v1.ListTokenChainResponse", [
            { no: 1, name: "entries", kind: "message", repeat: 2 /*RepeatType.UNPACKED*/, T: () => TokenChainEntry },
            { no: 2, name: "next_page_token", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
            { no: 3, name: "has_more", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }
        ]);
    }
    create(value) {
        const message = globalThis.Object.create((this.messagePrototype));
        message.entries = [];
        message.nextPageToken = "";
        message.hasMore = false;
        if (value !== undefined)
            reflectionMergePartial(this, message, value);
        return message;
    }
    internalBinaryRead(reader, length, options, target) {
        let message = target ?? this.create(), end = reader.pos + length;
        while (reader.pos < end) {
            let [fieldNo, wireType] = reader.tag();
            switch (fieldNo) {
                case /* repeated nimi.runtime.v1.TokenChainEntry entries */ 1:
                    message.entries.push(TokenChainEntry.internalBinaryRead(reader, reader.uint32(), options));
                    break;
                case /* string next_page_token */ 2:
                    message.nextPageToken = reader.string();
                    break;
                case /* bool has_more */ 3:
                    message.hasMore = reader.bool();
                    break;
                default:
                    let u = options.readUnknownField;
                    if (u === "throw")
                        throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
                    let d = reader.skip(wireType);
                    if (u !== false)
                        (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
            }
        }
        return message;
    }
    internalBinaryWrite(message, writer, options) {
        /* repeated nimi.runtime.v1.TokenChainEntry entries = 1; */
        for (let i = 0; i < message.entries.length; i++)
            TokenChainEntry.internalBinaryWrite(message.entries[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join();
        /* string next_page_token = 2; */
        if (message.nextPageToken !== "")
            writer.tag(2, WireType.LengthDelimited).string(message.nextPageToken);
        /* bool has_more = 3; */
        if (message.hasMore !== false)
            writer.tag(3, WireType.Varint).bool(message.hasMore);
        let u = options.writeUnknownFields;
        if (u !== false)
            (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
        return writer;
    }
}
/**
 * @generated MessageType for protobuf message nimi.runtime.v1.ListTokenChainResponse
 */
export const ListTokenChainResponse = new ListTokenChainResponse$Type();
/**
 * @generated ServiceType for protobuf service nimi.runtime.v1.RuntimeGrantService
 */
export const RuntimeGrantService = new ServiceType("nimi.runtime.v1.RuntimeGrantService", [
    { name: "AuthorizeExternalPrincipal", options: {}, I: AuthorizeExternalPrincipalRequest, O: AuthorizeExternalPrincipalResponse },
    { name: "ValidateAppAccessToken", options: {}, I: ValidateAppAccessTokenRequest, O: ValidateAppAccessTokenResponse },
    { name: "RevokeAppAccessToken", options: {}, I: RevokeAppAccessTokenRequest, O: Ack },
    { name: "IssueDelegatedAccessToken", options: {}, I: IssueDelegatedAccessTokenRequest, O: IssueDelegatedAccessTokenResponse },
    { name: "ListTokenChain", options: {}, I: ListTokenChainRequest, O: ListTokenChainResponse }
]);
//# sourceMappingURL=grant.js.map